From 350fa10077db05a695081ffa234fbc8a065b7813 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 8 Mar 2024 12:15:47 +0800 Subject: [PATCH 1/4] rename --- src/libs/actions/Report.ts | 2 +- src/libs/actions/Session/index.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) 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..cd133f7fef53 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -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,9 @@ 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]; - if ((routesCanAccessByAnonymousUser as string[]).includes(routeRemovedReportId)) { + if ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId)) { return true; } return false; @@ -986,7 +986,7 @@ export { toggleTwoFactorAuth, validateTwoFactorAuth, waitForUserSignIn, - canAccessRouteByAnonymousUser, + canAnonymousUserAccessRoute, signInWithSupportAuthToken, isSupportAuthToken, hasStashedSession, From c43b4ca64e01dc9e5c317b8f15be065ce0f03a73 Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 8 Mar 2024 12:24:22 +0800 Subject: [PATCH 2/4] allow anonymous user to access validate login page --- src/libs/actions/Session/index.ts | 3 ++- src/pages/ValidateLoginPage/index.tsx | 2 +- src/pages/ValidateLoginPage/index.website.tsx | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index cd133f7fef53..beae4ec5ebf8 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -949,8 +949,9 @@ const canAnonymousUserAccessRoute = (route: string) => { routeRemovedReportId = routeRemovedReportId.slice(1); } 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 ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId)) { + if ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId) || isMagicLink) { return true; } return false; 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; From bf0d428469f3c35d25ca74293507ee372b7dc1ef Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 8 Mar 2024 12:24:30 +0800 Subject: [PATCH 3/4] fix navigation --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index beae4ec5ebf8..b26ac3046a9d 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(); } } From 51f0e946e2bc615b0362bb9b27aebe2a0dd79b9b Mon Sep 17 00:00:00 2001 From: Bernhard Owen Josephus Date: Fri, 8 Mar 2024 12:40:47 +0800 Subject: [PATCH 4/4] prettier --- src/libs/actions/Session/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/Session/index.ts b/src/libs/actions/Session/index.ts index b26ac3046a9d..07bc7f3ed418 100644 --- a/src/libs/actions/Session/index.ts +++ b/src/libs/actions/Session/index.ts @@ -949,7 +949,7 @@ const canAnonymousUserAccessRoute = (route: string) => { routeRemovedReportId = routeRemovedReportId.slice(1); } 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}`); + const isMagicLink = CONST.REGEX.ROUTES.VALIDATE_LOGIN.test(`/${route}`); if ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId) || isMagicLink) { return true;