diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 94fe324d306a..8399070ed21b 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -2252,7 +2252,7 @@ function openReportFromDeepLink(url: string, isAuthenticated: boolean) { Navigation.waitForProtectedRoutes().then(() => { const route = ReportUtils.getRouteFromLink(url); - if (route && Session.isAnonymousUser() && !Session.canAccessRouteByAnonymousUser(route)) { + if (route && Session.isAnonymousUser() && !Session.canAnonymousUserAccessRoute(route)) { Session.signOutAndRedirectToSignIn(true); return; } diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index 6a0f53c3d058..07bc7f3ed418 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -925,7 +925,7 @@ function signInWithValidateCodeAndNavigate(accountID: number, validateCode: stri if (exitTo) { handleExitToNavigation(exitTo); } else { - Navigation.navigate(ROUTES.HOME); + Navigation.goBack(); } } @@ -935,7 +935,7 @@ function signInWithValidateCodeAndNavigate(accountID: number, validateCode: stri * @param {string} route */ -const canAccessRouteByAnonymousUser = (route: string) => { +const canAnonymousUserAccessRoute = (route: string) => { const reportID = ReportUtils.getReportIDFromLink(route); if (reportID) { return true; @@ -948,9 +948,10 @@ const canAccessRouteByAnonymousUser = (route: string) => { if (route.startsWith('/')) { routeRemovedReportId = routeRemovedReportId.slice(1); } - const routesCanAccessByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route, ROUTES.CONCIERGE]; + const routesAccessibleByAnonymousUser = [ROUTES.SIGN_IN_MODAL, ROUTES.REPORT_WITH_ID_DETAILS.route, ROUTES.REPORT_WITH_ID_DETAILS_SHARE_CODE.route, ROUTES.CONCIERGE]; + const isMagicLink = CONST.REGEX.ROUTES.VALIDATE_LOGIN.test(`/${route}`); - if ((routesCanAccessByAnonymousUser as string[]).includes(routeRemovedReportId)) { + if ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId) || isMagicLink) { return true; } return false; @@ -986,7 +987,7 @@ export { toggleTwoFactorAuth, validateTwoFactorAuth, waitForUserSignIn, - canAccessRouteByAnonymousUser, + canAnonymousUserAccessRoute, signInWithSupportAuthToken, isSupportAuthToken, hasStashedSession, diff --git a/src/pages/ValidateLoginPage/index.tsx b/src/pages/ValidateLoginPage/index.tsx index 2289547afe56..d7e975890186 100644 --- a/src/pages/ValidateLoginPage/index.tsx +++ b/src/pages/ValidateLoginPage/index.tsx @@ -16,7 +16,7 @@ function ValidateLoginPage({ useEffect(() => { // Wait till navigation becomes available Navigation.isNavigationReady().then(() => { - if (session?.authToken) { + if (session?.authToken && session?.authTokenType !== CONST.AUTH_TOKEN_TYPES.ANONYMOUS) { // If already signed in, do not show the validate code if not on web, // because we don't want to block the user with the interstitial page. if (exitTo) { diff --git a/src/pages/ValidateLoginPage/index.website.tsx b/src/pages/ValidateLoginPage/index.website.tsx index 866b061d964f..2acad7815754 100644 --- a/src/pages/ValidateLoginPage/index.website.tsx +++ b/src/pages/ValidateLoginPage/index.website.tsx @@ -20,7 +20,7 @@ function ValidateLoginPage({ }: ValidateLoginPageProps) { const login = credentials?.login; const autoAuthState = session?.autoAuthState ?? CONST.AUTO_AUTH_STATE.NOT_STARTED; - const isSignedIn = !!session?.authToken; + const isSignedIn = !!session?.authToken && session?.authTokenType !== CONST.AUTH_TOKEN_TYPES.ANONYMOUS; const is2FARequired = !!account?.requiresTwoFactorAuth; const cachedAccountID = credentials?.accountID;