diff --git a/examples/for-tests/src/App.js b/examples/for-tests/src/App.js index 048337ec8..079269b9c 100644 --- a/examples/for-tests/src/App.js +++ b/examples/for-tests/src/App.js @@ -458,6 +458,7 @@ SuperTokens.init({ apiDomain: getApiDomain(), websiteBasePath, }, + enableDebugLogs: true, languageTranslations: { translations: { en: { diff --git a/lib/build/multifactorauth-shared.js b/lib/build/multifactorauth-shared.js index dcbacf133..ed32c7683 100644 --- a/lib/build/multifactorauth-shared.js +++ b/lib/build/multifactorauth-shared.js @@ -236,14 +236,21 @@ var Session = /** @class */ (function (_super) { ) { return genericComponentOverrideContext.__awaiter(_this, void 0, void 0, function () { var invalidClaims, jsonContext, failureRedirectInfo, successContextStr, storedContext; - return genericComponentOverrideContext.__generator(this, function (_a) { - switch (_a.label) { + var _a; + return genericComponentOverrideContext.__generator(this, function (_b) { + switch (_b.label) { case 0: + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection called" + ); userContext = genericComponentOverrideContext.getNormalisedUserContext(userContext); return [4 /*yield*/, this.doesSessionExist({ userContext: userContext })]; case 1: // First we check if there is an active session - if (!_a.sent()) { + if (!_b.sent()) { + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection no session exists, so redirecting to auth" + ); // If there is none, we have no way of checking claims, so we redirect to the auth page // This can happen e.g.: if the user clicked on the email verification link in a browser without an active session return [ @@ -255,11 +262,24 @@ var Session = /** @class */ (function (_super) { }), ]; } + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection validating claims" + ); return [4 /*yield*/, this.validateClaims({ userContext: userContext })]; case 2: - invalidClaims = _a.sent(); + invalidClaims = _b.sent(); + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: invalid claims: ".concat( + invalidClaims.map(function (c) { + return c.id; + }) + ) + ); if (!(invalidClaims.length > 0)) return [3 /*break*/, 6]; if (!(successRedirectContext !== undefined)) return [3 /*break*/, 4]; + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: saving successRedirectContext" + ); jsonContext = JSON.stringify({ successRedirectContext: successRedirectContext, redirectToPath: redirectToPath, @@ -272,8 +292,8 @@ var Session = /** @class */ (function (_super) { ), ]; case 3: - _a.sent(); - _a.label = 4; + _b.sent(); + _b.label = 4; case 4: return [ 4 /*yield*/, @@ -283,9 +303,19 @@ var Session = /** @class */ (function (_super) { }), ]; case 5: - failureRedirectInfo = _a.sent(); + failureRedirectInfo = _b.sent(); // if redirectPath is string that means failed claim had callback that returns path, we redirect there otherwise continue if (failureRedirectInfo.redirectPath !== undefined) { + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: failureRedirection: " + .concat(failureRedirectInfo.redirectPath, " (") + .concat( + (_a = failureRedirectInfo.failedClaim) === null || _a === void 0 + ? void 0 + : _a.id, + ")" + ) + ); // the validation part can throw, but this is handled in all places where this is called, // since getFailureRedirectionInfo can also throw if ( @@ -306,9 +336,15 @@ var Session = /** @class */ (function (_super) { ), ]; } - _a.label = 6; + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: no redirectPath based on validation errors" + ); + _b.label = 6; case 6: if (!(successRedirectContext === undefined)) return [3 /*break*/, 13]; + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: loading successRedirectContext from storage" + ); return [ 4 /*yield*/, genericComponentOverrideContext.getLocalStorage( @@ -316,11 +352,11 @@ var Session = /** @class */ (function (_super) { ), ]; case 7: - successContextStr = _a.sent(); + successContextStr = _b.sent(); if (!(successContextStr !== null)) return [3 /*break*/, 12]; - _a.label = 8; + _b.label = 8; case 8: - _a.trys.push([8, , 9, 11]); + _b.trys.push([8, , 9, 11]); storedContext = JSON.parse(successContextStr); successRedirectContext = storedContext.successRedirectContext; // if we have a redirectToPath set in the queryparams that takes priority over the stored value @@ -336,11 +372,14 @@ var Session = /** @class */ (function (_super) { ), ]; case 10: - _a.sent(); + _b.sent(); return [7 /*endfinally*/]; case 11: return [3 /*break*/, 13]; case 12: + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: using default because loading failed" + ); // If there was nothing in localstorage we set a default // this can happen if the user visited email verification screen without an auth recipe redirecting them there // but already had the email verified and an active session @@ -351,14 +390,22 @@ var Session = /** @class */ (function (_super) { isNewRecipeUser: false, newSessionCreated: false, }; - _a.label = 13; + _b.label = 13; case 13: if (successRedirectContext === undefined) { throw new Error("This should never happen: successRedirectContext undefined "); } if (redirectToPath !== undefined) { + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: using redirectToPath directly passed here" + ); successRedirectContext.redirectToPath = redirectToPath; } + genericComponentOverrideContext.logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection: redirecting with context: ".concat( + JSON.stringify(successRedirectContext) + ) + ); return [ 2 /*return*/, genericComponentOverrideContext.SuperTokens.getInstanceOrThrow().redirect( diff --git a/lib/ts/recipe/session/recipe.tsx b/lib/ts/recipe/session/recipe.tsx index 5c628333b..4335f3e99 100644 --- a/lib/ts/recipe/session/recipe.tsx +++ b/lib/ts/recipe/session/recipe.tsx @@ -48,6 +48,7 @@ import type { import type { ClaimValidationError, SessionClaimValidator } from "supertokens-web-js/recipe/session"; import type { SessionClaim } from "supertokens-web-js/recipe/session"; import type { RecipeEvent } from "supertokens-web-js/recipe/session/types"; +import { logDebugMessage } from "../../logger"; export default class Session extends RecipeModule { static instance?: Session; @@ -132,9 +133,13 @@ export default class Session extends RecipeModule => { + logDebugMessage("validateGlobalClaimsAndHandleSuccessRedirection called"); userContext = getNormalisedUserContext(userContext); // First we check if there is an active session if (!(await this.doesSessionExist({ userContext }))) { + logDebugMessage( + "validateGlobalClaimsAndHandleSuccessRedirection no session exists, so redirecting to auth" + ); // If there is none, we have no way of checking claims, so we redirect to the auth page // This can happen e.g.: if the user clicked on the email verification link in a browser without an active session return SuperTokens.getInstanceOrThrow().redirectToAuth({ @@ -144,11 +149,16 @@ export default class Session extends RecipeModule c.id)}` + ); if (invalidClaims.length > 0) { if (successRedirectContext !== undefined) { + logDebugMessage(`validateGlobalClaimsAndHandleSuccessRedirection: saving successRedirectContext`); // if we have to redirect and we have success context we wanted to use we save it in localstorage // this way after the other page did solved the validation error it can continue // the sign in process by calling this function without passing the redirect info @@ -164,6 +174,9 @@ export default class Session extends RecipeModule { const log = consoleObj.text(); - // console.log(log); + console.log(log); if (log.startsWith("ST_LOGS")) { consoleLogs.push(log); }