Skip to content

Commit

Permalink
Merge pull request #42130 from bernhardoj/fix/41333-dont-navigate-to-…
Browse files Browse the repository at this point in the history
…public-screen-after-sign-in

Don't navigate to public screen deep link after sign in
  • Loading branch information
johnmlee101 authored May 29, 2024
2 parents df0173e + 3445245 commit 2749f58
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
21 changes: 12 additions & 9 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,20 @@ function getUrlWithBackToParam<TUrl extends string>(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',

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -876,7 +879,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
Expand Down
13 changes: 10 additions & 3 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -2481,8 +2482,9 @@ function toggleEmojiReaction(

function openReportFromDeepLink(url: string, shouldNavigate = true) {
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);

Expand All @@ -2495,12 +2497,17 @@ function openReportFromDeepLink(url: string, shouldNavigate = true) {
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;
Expand Down
8 changes: 8 additions & 0 deletions src/libs/isPublicScreenRoute.ts
Original file line number Diff line number Diff line change
@@ -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);
});
}

0 comments on commit 2749f58

Please sign in to comment.