diff --git a/lib/build/oauth2providerprebuiltui.js b/lib/build/oauth2providerprebuiltui.js index 7f7a99de6..8edda1d3d 100644 --- a/lib/build/oauth2providerprebuiltui.js +++ b/lib/build/oauth2providerprebuiltui.js @@ -343,13 +343,17 @@ var OAuth2LogoutScreen = function (props) { }; var TryRefreshPage$1 = function (props) { - var _a; + var _a, _b; var rethrowInRender = genericComponentOverrideContext.useRethrowInRender(); var sessionContext = React.useContext(uiEntry.SessionContext); var loginChallenge = (_a = genericComponentOverrideContext.getQueryParams("loginChallenge")) !== null && _a !== void 0 ? _a : undefined; + var forceRefresh = + (_b = genericComponentOverrideContext.getQueryParams("forceRefresh")) !== null && _b !== void 0 + ? _b + : undefined; var userContext = uiEntry.useUserContext(); if (props.userContext !== undefined) { userContext = props.userContext; @@ -357,49 +361,60 @@ var TryRefreshPage$1 = function (props) { React__namespace.useEffect( function () { if (sessionContext.loading === false) { - if (loginChallenge) { - (function () { - return genericComponentOverrideContext.__awaiter(this, void 0, void 0, function () { - var frontendRedirectTo; - return genericComponentOverrideContext.__generator(this, function (_a) { - switch (_a.label) { - case 0: - return [ - 4 /*yield*/, - props.recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ - loginChallenge: loginChallenge, - userContext: userContext, - }), - ]; - case 1: - frontendRedirectTo = _a.sent().frontendRedirectTo; - return [ - 2 /*return*/, - props.recipe.redirect( - { - action: "CONTINUE_OAUTH2_AFTER_REFRESH", - frontendRedirectTo: frontendRedirectTo, - tenantIdFromQueryParams: - genericComponentOverrideContext.getTenantIdFromQueryParams(), - recipeId: "oauth2provider", - }, - props.navigate, - {}, - userContext - ), - ]; - } - }); + (function () { + return genericComponentOverrideContext.__awaiter(this, void 0, void 0, function () { + var frontendRedirectTo; + return genericComponentOverrideContext.__generator(this, function (_a) { + switch (_a.label) { + case 0: + if (!forceRefresh) return [3 /*break*/, 2]; + return [4 /*yield*/, session.attemptRefreshingSession()]; + case 1: + _a.sent(); + _a.label = 2; + case 2: + if (!loginChallenge) return [3 /*break*/, 4]; + return [ + 4 /*yield*/, + props.recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ + loginChallenge: loginChallenge, + userContext: userContext, + }), + ]; + case 3: + frontendRedirectTo = _a.sent().frontendRedirectTo; + return [ + 2 /*return*/, + props.recipe.redirect( + { + action: "CONTINUE_OAUTH2_AFTER_REFRESH", + frontendRedirectTo: frontendRedirectTo, + tenantIdFromQueryParams: + genericComponentOverrideContext.getTenantIdFromQueryParams(), + recipeId: "oauth2provider", + }, + props.navigate, + {}, + userContext + ), + ]; + case 4: + return [ + 4 /*yield*/, + uiEntry.redirectToAuth({ + redirectBack: false, + userContext: userContext, + }), + ]; + case 5: + _a.sent(); + _a.label = 6; + case 6: + return [2 /*return*/]; + } }); - })().catch(rethrowInRender); - } else { - void genericComponentOverrideContext.SuperTokens.getInstanceOrThrow() - .redirectToAuth({ - userContext: userContext, - redirectBack: false, - }) - .catch(rethrowInRender); - } + }); + })().catch(rethrowInRender); } }, [loginChallenge, props.recipe, props.navigate, userContext, sessionContext] diff --git a/lib/ts/recipe/oauth2provider/components/features/tryRefreshPage/index.tsx b/lib/ts/recipe/oauth2provider/components/features/tryRefreshPage/index.tsx index ddb045694..7c224c8c6 100644 --- a/lib/ts/recipe/oauth2provider/components/features/tryRefreshPage/index.tsx +++ b/lib/ts/recipe/oauth2provider/components/features/tryRefreshPage/index.tsx @@ -19,12 +19,13 @@ import * as React from "react"; import { useContext, Fragment } from "react"; +import { redirectToAuth } from "../../../../.."; import FeatureWrapper from "../../../../../components/featureWrapper"; import SuperTokens from "../../../../../superTokens"; import { useUserContext } from "../../../../../usercontext"; import { getQueryParams, getTenantIdFromQueryParams, useRethrowInRender } from "../../../../../utils"; import DynamicLoginMethodsSpinner from "../../../../multitenancy/components/features/dynamicLoginMethodsSpinner"; -import { SessionContext } from "../../../../session"; +import { SessionContext, attemptRefreshingSession } from "../../../../session"; import { defaultTranslationsOAuth2Provider } from "../../themes/translations"; import type { FeatureBaseProps, UserContext } from "../../../../../types"; @@ -41,6 +42,7 @@ export const TryRefreshPage: React.FC = (props) => { const rethrowInRender = useRethrowInRender(); const sessionContext = useContext(SessionContext); const loginChallenge = getQueryParams("loginChallenge") ?? undefined; + const forceRefresh = getQueryParams("forceRefresh") ?? undefined; let userContext = useUserContext(); if (props.userContext !== undefined) { userContext = props.userContext; @@ -48,8 +50,11 @@ export const TryRefreshPage: React.FC = (props) => { React.useEffect(() => { if (sessionContext.loading === false) { - if (loginChallenge) { - (async function () { + (async function () { + if (forceRefresh) { + await attemptRefreshingSession(); + } + if (loginChallenge) { const { frontendRedirectTo } = await props.recipe.webJSRecipe.getRedirectURLToContinueOAuthFlow({ loginChallenge, userContext, @@ -65,15 +70,13 @@ export const TryRefreshPage: React.FC = (props) => { {}, userContext ); - })().catch(rethrowInRender); - } else { - void SuperTokens.getInstanceOrThrow() - .redirectToAuth({ - userContext, + } else { + await redirectToAuth({ redirectBack: false, - }) - .catch(rethrowInRender); - } + userContext, + }); + } + })().catch(rethrowInRender); } }, [loginChallenge, props.recipe, props.navigate, userContext, sessionContext]);