diff --git a/lib/build/index2.js b/lib/build/index2.js index 8bb9327cb..b93bb4190 100644 --- a/lib/build/index2.js +++ b/lib/build/index2.js @@ -1008,22 +1008,45 @@ var AuthPageInner = function (props) { }, [loadedDynamicLoginMethods, setLoadedDynamicLoginMethods] ); - React.useEffect( + genericComponentOverrideContext.useOnMountAPICall( function () { - if (oauth2ClientInfo) { - return; - } - var oauth2Recipe = recipe.OAuth2Provider.getInstance(); - if (oauth2Recipe !== undefined && loginChallenge !== null) { - void recipe.OAuth2Provider.getInstanceOrThrow() - .webJSRecipe.getLoginChallengeInfo({ loginChallenge: loginChallenge, userContext: userContext }) - .then(function (_a) { - var info = _a.info; - return setOAuth2ClientInfo(info); - }); - } + return genericComponentOverrideContext.__awaiter(void 0, void 0, void 0, function () { + var oauth2Recipe; + return genericComponentOverrideContext.__generator(this, function (_a) { + if (oauth2ClientInfo) { + return [2 /*return*/]; + } + oauth2Recipe = recipe.OAuth2Provider.getInstance(); + if (oauth2Recipe !== undefined && loginChallenge !== null) { + return [ + 2 /*return*/, + oauth2Recipe.webJSRecipe.getLoginChallengeInfo({ + loginChallenge: loginChallenge, + userContext: userContext, + }), + ]; + } + return [2 /*return*/, undefined]; + }); + }); }, - [setOAuth2ClientInfo, loginChallenge, oauth2ClientInfo] + function (info) { + return genericComponentOverrideContext.__awaiter(void 0, void 0, void 0, function () { + return genericComponentOverrideContext.__generator(this, function (_a) { + if (info !== undefined) { + setOAuth2ClientInfo(info.info); + } + return [2 /*return*/]; + }); + }); + }, + function () { + return genericComponentOverrideContext.SuperTokens.getInstanceOrThrow().redirectToAuth({ + navigate: props.navigate, + redirectBack: false, + userContext: userContext, + }); + } ); React.useEffect( function () { @@ -1041,7 +1064,8 @@ var AuthPageInner = function (props) { types.Session.getInstanceOrThrow().config.onHandleEvent({ action: "SESSION_ALREADY_EXISTS", }); - if (loginChallenge !== null) { + var oauth2Recipe_1 = recipe.OAuth2Provider.getInstance(); + if (loginChallenge !== null && oauth2Recipe_1 !== undefined) { (function () { return genericComponentOverrideContext.__awaiter(this, void 0, void 0, function () { var frontendRedirectTo; @@ -1050,12 +1074,10 @@ var AuthPageInner = function (props) { case 0: return [ 4 /*yield*/, - recipe.OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow( - { - loginChallenge: loginChallenge, - userContext: userContext, - } - ), + oauth2Recipe_1.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge: loginChallenge, + userContext: userContext, + }), ]; case 1: frontendRedirectTo = _a.sent().frontendRedirectTo; @@ -1158,11 +1180,12 @@ var AuthPageInner = function (props) { var onAuthSuccess = React.useCallback( function (ctx) { return genericComponentOverrideContext.__awaiter(void 0, void 0, void 0, function () { - var frontendRedirectTo; + var oauth2Recipe, frontendRedirectTo; return genericComponentOverrideContext.__generator(this, function (_a) { switch (_a.label) { case 0: - if (loginChallenge === null) { + oauth2Recipe = recipe.OAuth2Provider.getInstance(); + if (loginChallenge === null || oauth2Recipe === undefined) { return [ 2 /*return*/, types.Session.getInstanceOrThrow().validateGlobalClaimsAndHandleSuccessRedirection( @@ -1185,12 +1208,10 @@ var AuthPageInner = function (props) { } return [ 4 /*yield*/, - recipe.OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow( - { - loginChallenge: loginChallenge, - userContext: userContext, - } - ), + oauth2Recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge: loginChallenge, + userContext: userContext, + }), ]; case 1: frontendRedirectTo = _a.sent().frontendRedirectTo; diff --git a/lib/build/thirdpartyprebuiltui.js b/lib/build/thirdpartyprebuiltui.js index 3bac81205..bdfe1d6ae 100644 --- a/lib/build/thirdpartyprebuiltui.js +++ b/lib/build/thirdpartyprebuiltui.js @@ -437,7 +437,13 @@ var SignInAndUpCallback$1 = function (props) { var response = _a.response, payloadBeforeCall = _a.payloadBeforeCall; return genericComponentOverrideContext.__awaiter(void 0, void 0, void 0, function () { - var payloadAfterCall, stateResponse, redirectToPath, loginChallenge, frontendRedirectTo, e_1; + var payloadAfterCall, + stateResponse, + redirectToPath, + loginChallenge, + oauth2Recipe, + frontendRedirectTo, + e_1; return genericComponentOverrideContext.__generator(this, function (_c) { switch (_c.label) { case 0: @@ -495,18 +501,17 @@ var SignInAndUpCallback$1 = function (props) { stateResponse === null || stateResponse === void 0 ? void 0 : stateResponse.oauth2LoginChallenge; - if (!(loginChallenge !== undefined)) return [3 /*break*/, 9]; + oauth2Recipe = recipe$1.OAuth2Provider.getInstance(); + if (!(loginChallenge !== undefined && oauth2Recipe !== undefined)) return [3 /*break*/, 9]; _c.label = 5; case 5: _c.trys.push([5, 7, , 8]); return [ 4 /*yield*/, - recipe$1.OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow( - { - loginChallenge: loginChallenge, - userContext: userContext, - } - ), + oauth2Recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge: loginChallenge, + userContext: userContext, + }), ]; case 6: frontendRedirectTo = _c.sent().frontendRedirectTo; diff --git a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx index db7927cfa..e5aabf21d 100644 --- a/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx +++ b/lib/ts/recipe/authRecipe/components/feature/authPage/authPage.tsx @@ -30,6 +30,7 @@ import { getTenantIdFromQueryParams, mergeObjects, updateQueryParam, + useOnMountAPICall, useRethrowInRender, } from "../../../../../utils"; import MultiFactorAuth from "../../../../multifactorauth/recipe"; @@ -174,17 +175,30 @@ const AuthPageInner: React.FC = (props) => { ); }, [loadedDynamicLoginMethods, setLoadedDynamicLoginMethods]); - useEffect(() => { - if (oauth2ClientInfo) { - return; - } - const oauth2Recipe = OAuth2Provider.getInstance(); - if (oauth2Recipe !== undefined && loginChallenge !== null) { - void OAuth2Provider.getInstanceOrThrow() - .webJSRecipe.getLoginChallengeInfo({ loginChallenge, userContext }) - .then(({ info }) => setOAuth2ClientInfo(info)); + useOnMountAPICall( + async () => { + if (oauth2ClientInfo) { + return; + } + const oauth2Recipe = OAuth2Provider.getInstance(); + if (oauth2Recipe !== undefined && loginChallenge !== null) { + return oauth2Recipe.webJSRecipe.getLoginChallengeInfo({ loginChallenge, userContext }); + } + return undefined; + }, + async (info) => { + if (info !== undefined) { + setOAuth2ClientInfo(info.info); + } + }, + () => { + return SuperTokens.getInstanceOrThrow().redirectToAuth({ + navigate: props.navigate, + redirectBack: false, + userContext, + }); } - }, [setOAuth2ClientInfo, loginChallenge, oauth2ClientInfo]); + ); useEffect(() => { if (sessionLoadedAndNotRedirecting) { @@ -202,15 +216,14 @@ const AuthPageInner: React.FC = (props) => { Session.getInstanceOrThrow().config.onHandleEvent({ action: "SESSION_ALREADY_EXISTS", }); - if (loginChallenge !== null) { + const oauth2Recipe = OAuth2Provider.getInstance(); + if (loginChallenge !== null && oauth2Recipe !== undefined) { (async function () { const { frontendRedirectTo } = - await OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow( - { - loginChallenge, - userContext, - } - ); + await oauth2Recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge, + userContext, + }); return Session.getInstanceOrThrow().validateGlobalClaimsAndHandleSuccessRedirection( { action: "SUCCESS_OAUTH2", @@ -299,7 +312,8 @@ const AuthPageInner: React.FC = (props) => { const onAuthSuccess = useCallback( async (ctx: AuthSuccessContext) => { - if (loginChallenge === null) { + const oauth2Recipe = OAuth2Provider.getInstance(); + if (loginChallenge === null || oauth2Recipe === undefined) { return Session.getInstanceOrThrow().validateGlobalClaimsAndHandleSuccessRedirection( { ...ctx, @@ -313,11 +327,10 @@ const AuthPageInner: React.FC = (props) => { props.navigate ); } - const { frontendRedirectTo } = - await OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow({ - loginChallenge, - userContext, - }); + const { frontendRedirectTo } = await oauth2Recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge, + userContext, + }); return Session.getInstanceOrThrow().validateGlobalClaimsAndHandleSuccessRedirection( { ...ctx, diff --git a/lib/ts/recipe/thirdparty/components/features/signInAndUpCallback/index.tsx b/lib/ts/recipe/thirdparty/components/features/signInAndUpCallback/index.tsx index 9a5d19d05..e2be0f280 100644 --- a/lib/ts/recipe/thirdparty/components/features/signInAndUpCallback/index.tsx +++ b/lib/ts/recipe/thirdparty/components/features/signInAndUpCallback/index.tsx @@ -107,13 +107,15 @@ const SignInAndUpCallback: React.FC = (props) => { const redirectToPath = stateResponse === undefined ? undefined : stateResponse.redirectToPath; const loginChallenge = stateResponse?.oauth2LoginChallenge; - if (loginChallenge !== undefined) { + const oauth2Recipe = OAuth2Provider.getInstance(); + if (loginChallenge !== undefined && oauth2Recipe !== undefined) { try { - const { frontendRedirectTo } = - await OAuth2Provider.getInstanceOrThrow().webJSRecipe.getRedirectURLToContinueOAuthFlow({ + const { frontendRedirectTo } = await oauth2Recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow( + { loginChallenge, userContext, - }); + } + ); return Session.getInstanceOrThrow().validateGlobalClaimsAndHandleSuccessRedirection( { action: "SUCCESS_OAUTH2",