diff --git a/src/ROUTES.ts b/src/ROUTES.ts index 2bc04c4a99ea..034c427c8d9e 100644 --- a/src/ROUTES.ts +++ b/src/ROUTES.ts @@ -14,10 +14,20 @@ function getUrlWithBackToParam(url: TUrl, backTo?: string): return `${url}${backToParam}` as const; } -const ROUTES = { +const PUBLIC_SCREENS_ROUTES = { // If the user opens this route, we'll redirect them to the path saved in the last visited path or to the home page if the last visited path is empty. ROOT: '', + TRANSITION_BETWEEN_APPS: 'transition', + CONNECTION_COMPLETE: 'connection-complete', + VALIDATE_LOGIN: 'v/:accountID/:validateCode', + UNLINK_LOGIN: 'u/:accountID/:validateCode', + APPLE_SIGN_IN: 'sign-in-with-apple', + GOOGLE_SIGN_IN: 'sign-in-with-google', + SAML_SIGN_IN: 'sign-in-with-saml', +} as const; +const ROUTES = { + ...PUBLIC_SCREENS_ROUTES, // This route renders the list of reports. HOME: 'home', @@ -53,18 +63,11 @@ const ROUTES = { getRoute: (accountID: string | number) => `a/${accountID}/avatar` as const, }, - TRANSITION_BETWEEN_APPS: 'transition', - VALIDATE_LOGIN: 'v/:accountID/:validateCode', - CONNECTION_COMPLETE: 'connection-complete', GET_ASSISTANCE: { route: 'get-assistance/:taskID', getRoute: (taskID: string, backTo: string) => getUrlWithBackToParam(`get-assistance/${taskID}`, backTo), }, - UNLINK_LOGIN: 'u/:accountID/:validateCode', - APPLE_SIGN_IN: 'sign-in-with-apple', - GOOGLE_SIGN_IN: 'sign-in-with-google', DESKTOP_SIGN_IN_REDIRECT: 'desktop-signin-redirect', - SAML_SIGN_IN: 'sign-in-with-saml', // This is a special validation URL that will take the user to /workspace/new after validation. This is used // when linking users from e.com in order to share a session in this app. @@ -875,7 +878,7 @@ const HYBRID_APP_ROUTES = { MONEY_REQUEST_SUBMIT_CREATE: '/submit/new/scan', } as const; -export {HYBRID_APP_ROUTES, getUrlWithBackToParam}; +export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES}; export default ROUTES; // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 12667db28f0f..9cd931d541e1 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -57,6 +57,7 @@ import {prepareDraftComment} from '@libs/DraftCommentUtils'; import * as EmojiUtils from '@libs/EmojiUtils'; import * as Environment from '@libs/Environment/Environment'; import * as ErrorUtils from '@libs/ErrorUtils'; +import isPublicScreenRoute from '@libs/isPublicScreenRoute'; import * as Localize from '@libs/Localize'; import Log from '@libs/Log'; import Navigation from '@libs/Navigation/Navigation'; @@ -2480,8 +2481,9 @@ function toggleEmojiReaction( function openReportFromDeepLink(url: string) { const reportID = ReportUtils.getReportIDFromLink(url); + const isAuthenticated = Session.hasAuthToken(); - if (reportID && !Session.hasAuthToken()) { + if (reportID && !isAuthenticated) { // Call the OpenReport command to check in the server if it's a public room. If so, we'll open it as an anonymous user openReport(reportID, '', [], {}, '0', true); @@ -2494,12 +2496,17 @@ function openReportFromDeepLink(url: string) { Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false); } + const route = ReportUtils.getRouteFromLink(url); + + // If we are not authenticated and are navigating to a public screen, we don't want to navigate again to the screen after sign-in/sign-up + if (!isAuthenticated && isPublicScreenRoute(route)) { + return; + } + // Navigate to the report after sign-in/sign-up. InteractionManager.runAfterInteractions(() => { Session.waitForUserSignIn().then(() => { Navigation.waitForProtectedRoutes().then(() => { - const route = ReportUtils.getRouteFromLink(url); - if (route && Session.isAnonymousUser() && !Session.canAnonymousUserAccessRoute(route)) { Session.signOutAndRedirectToSignIn(true); return; diff --git a/src/libs/isPublicScreenRoute.ts b/src/libs/isPublicScreenRoute.ts new file mode 100644 index 000000000000..e2c5ca5944eb --- /dev/null +++ b/src/libs/isPublicScreenRoute.ts @@ -0,0 +1,8 @@ +import {PUBLIC_SCREENS_ROUTES} from '@src/ROUTES'; + +export default function isPublicScreenRoute(route: string) { + return Object.values(PUBLIC_SCREENS_ROUTES).some((screenRoute) => { + const routeRegex = new RegExp(`^${screenRoute.replace(/:\w+/g, '\\w+')}$`); + return routeRegex.test(route); + }); +}