From 6f474554df46d57da948b1d19a154308e9f0873f Mon Sep 17 00:00:00 2001 From: Mihaly Lengyel Date: Mon, 30 Sep 2024 18:49:39 +0200 Subject: [PATCH] feat: added more debug logging --- .circleci/setupAndTestWithAuthReact.sh | 2 +- lib/build/authUtils.js | 33 ++++++++++++++++-------- lib/ts/authUtils.ts | 35 ++++++++++++++++++-------- 3 files changed, 47 insertions(+), 23 deletions(-) diff --git a/.circleci/setupAndTestWithAuthReact.sh b/.circleci/setupAndTestWithAuthReact.sh index 5df2f38a2..d2edfa98e 100755 --- a/.circleci/setupAndTestWithAuthReact.sh +++ b/.circleci/setupAndTestWithAuthReact.sh @@ -110,7 +110,7 @@ cd ../../../supertokens-auth-react/ # flag will not be checked because Auth0 is used as a provider so that the Thirdparty tests can run reliably. # In versions lower than 0.18 Github is used as the provider. -MOCHA_FILE=test_report/report_node.xml SKIP_OAUTH=true npm run test-with-non-node +DEBUG=com.supertokens MOCHA_FILE=test_report/report_node.xml SKIP_OAUTH=true npm run test-with-non-node if [[ $? -ne 0 ]] then mkdir -p ../project/test_report/screenshots diff --git a/lib/build/authUtils.js b/lib/build/authUtils.js index e48336c45..ed05a6b3d 100644 --- a/lib/build/authUtils.js +++ b/lib/build/authUtils.js @@ -898,17 +898,28 @@ exports.AuthUtils = { const overwriteSessionDuringSignInUp = recipe_3.default .getInstanceOrThrowError() .getNormalisedOverwriteSessionDuringSignInUp(req); - return shouldTryLinkingWithSessionUser !== false || overwriteSessionDuringSignInUp === false - ? await session_1.default.getSession( - req, - res, - { - sessionRequired: shouldTryLinkingWithSessionUser === true, - overrideGlobalClaimValidators: () => [], - }, - userContext - ) - : undefined; + if (shouldTryLinkingWithSessionUser === false) { + logger_1.logDebugMessage( + "loadSessionInAuthAPIIfNeeded: skipping session loading because shouldTryLinkingWithSessionUser is false" + ); + return undefined; + } + if (overwriteSessionDuringSignInUp === false) { + logger_1.logDebugMessage( + "loadSessionInAuthAPIIfNeeded: skipping session loading because overwriteSessionDuringSignInUp is false" + ); + return undefined; + } + logger_1.logDebugMessage("loadSessionInAuthAPIIfNeeded: loading session"); + return await session_1.default.getSession( + req, + res, + { + sessionRequired: shouldTryLinkingWithSessionUser === true, + overrideGlobalClaimValidators: () => [], + }, + userContext + ); }, }; async function filterOutInvalidSecondFactorsOrThrowIfAllAreInvalid( diff --git a/lib/ts/authUtils.ts b/lib/ts/authUtils.ts index b71d7eba3..ccce5e6c3 100644 --- a/lib/ts/authUtils.ts +++ b/lib/ts/authUtils.ts @@ -1021,17 +1021,30 @@ export const AuthUtils = { req ); - return shouldTryLinkingWithSessionUser !== false || overwriteSessionDuringSignInUp === false - ? await Session.getSession( - req, - res, - { - sessionRequired: shouldTryLinkingWithSessionUser === true, - overrideGlobalClaimValidators: () => [], - }, - userContext - ) - : undefined; + if (shouldTryLinkingWithSessionUser === false) { + logDebugMessage( + "loadSessionInAuthAPIIfNeeded: skipping session loading because shouldTryLinkingWithSessionUser is false" + ); + return undefined; + } + + if (overwriteSessionDuringSignInUp === false) { + logDebugMessage( + "loadSessionInAuthAPIIfNeeded: skipping session loading because overwriteSessionDuringSignInUp is false" + ); + return undefined; + } + logDebugMessage("loadSessionInAuthAPIIfNeeded: loading session"); + + return await Session.getSession( + req, + res, + { + sessionRequired: shouldTryLinkingWithSessionUser === true, + overrideGlobalClaimValidators: () => [], + }, + userContext + ); }, };