From 10f4fd11186ead6848ad55907d174f7205f6f36f Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Thu, 3 Oct 2024 08:21:27 +0530 Subject: [PATCH] [web] Fix recover redirect Ref: 59bf51346cd01e17f07d93c100ffab423a07cb54 --- web/packages/accounts/pages/verify.tsx | 8 ++++++-- web/packages/accounts/services/redirect.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/web/packages/accounts/pages/verify.tsx b/web/packages/accounts/pages/verify.tsx index 98a54adf8e..d6b0d574c1 100644 --- a/web/packages/accounts/pages/verify.tsx +++ b/web/packages/accounts/pages/verify.tsx @@ -16,8 +16,8 @@ import SingleInputForm, { import { ApiError } from "@ente/shared/error"; import localForage from "@ente/shared/storage/localForage"; import { - LS_KEYS, getData, + LS_KEYS, setData, setLSUser, } from "@ente/shared/storage/localStorage"; @@ -40,7 +40,7 @@ import { openPasskeyVerificationURL, passkeyVerificationRedirectURL, } from "../services/passkey"; -import { unstashRedirect } from "../services/redirect"; +import { stashedRedirect, unstashRedirect } from "../services/redirect"; import { configureSRP } from "../services/srp"; import type { PageProps } from "../types/page"; import type { SRPAttributes, SRPSetupAttributes } from "../types/srp"; @@ -59,6 +59,7 @@ const Page: React.FC = ({ appContext }) => { useEffect(() => { const main = async () => { const user: User = getData(LS_KEYS.USER); + const redirect = await redirectionIfNeeded(user); if (redirect) { router.push(redirect); @@ -265,6 +266,9 @@ const redirectionIfNeeded = async (user: User | undefined) => { return PAGES.CREDENTIALS; } + // If we're coming here during the recover flow, do not redirect. + if (stashedRedirect() == PAGES.RECOVER) return undefined; + // The user might have email verification disabled, but after previously // entering their email on the login screen, they might've closed the tab // before proceeding (or opened a us in a new tab at this point). diff --git a/web/packages/accounts/services/redirect.ts b/web/packages/accounts/services/redirect.ts index 8d102c94a5..d270e03a64 100644 --- a/web/packages/accounts/services/redirect.ts +++ b/web/packages/accounts/services/redirect.ts @@ -17,6 +17,7 @@ let _stashedRedirect: string | undefined; /** * An in-memory redirect saved during the login flow (mostly). */ +export const stashedRedirect = () => _stashedRedirect; export const stashRedirect = (r: string) => (_stashedRedirect = r); export const unstashRedirect = () => { const r = _stashedRedirect;