Skip to content

Commit 2749f58

Browse files
authored
Merge pull request #42130 from bernhardoj/fix/41333-dont-navigate-to-public-screen-after-sign-in
Don't navigate to public screen deep link after sign in
2 parents df0173e + 3445245 commit 2749f58

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

src/ROUTES.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,20 @@ function getUrlWithBackToParam<TUrl extends string>(url: TUrl, backTo?: string):
1414
return `${url}${backToParam}` as const;
1515
}
1616

17-
const ROUTES = {
17+
const PUBLIC_SCREENS_ROUTES = {
1818
// 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.
1919
ROOT: '',
20+
TRANSITION_BETWEEN_APPS: 'transition',
21+
CONNECTION_COMPLETE: 'connection-complete',
22+
VALIDATE_LOGIN: 'v/:accountID/:validateCode',
23+
UNLINK_LOGIN: 'u/:accountID/:validateCode',
24+
APPLE_SIGN_IN: 'sign-in-with-apple',
25+
GOOGLE_SIGN_IN: 'sign-in-with-google',
26+
SAML_SIGN_IN: 'sign-in-with-saml',
27+
} as const;
2028

29+
const ROUTES = {
30+
...PUBLIC_SCREENS_ROUTES,
2131
// This route renders the list of reports.
2232
HOME: 'home',
2333

@@ -53,18 +63,11 @@ const ROUTES = {
5363
getRoute: (accountID: string | number) => `a/${accountID}/avatar` as const,
5464
},
5565

56-
TRANSITION_BETWEEN_APPS: 'transition',
57-
VALIDATE_LOGIN: 'v/:accountID/:validateCode',
58-
CONNECTION_COMPLETE: 'connection-complete',
5966
GET_ASSISTANCE: {
6067
route: 'get-assistance/:taskID',
6168
getRoute: (taskID: string, backTo: string) => getUrlWithBackToParam(`get-assistance/${taskID}`, backTo),
6269
},
63-
UNLINK_LOGIN: 'u/:accountID/:validateCode',
64-
APPLE_SIGN_IN: 'sign-in-with-apple',
65-
GOOGLE_SIGN_IN: 'sign-in-with-google',
6670
DESKTOP_SIGN_IN_REDIRECT: 'desktop-signin-redirect',
67-
SAML_SIGN_IN: 'sign-in-with-saml',
6871

6972
// This is a special validation URL that will take the user to /workspace/new after validation. This is used
7073
// when linking users from e.com in order to share a session in this app.
@@ -876,7 +879,7 @@ const HYBRID_APP_ROUTES = {
876879
MONEY_REQUEST_SUBMIT_CREATE: '/submit/new/scan',
877880
} as const;
878881

879-
export {HYBRID_APP_ROUTES, getUrlWithBackToParam};
882+
export {HYBRID_APP_ROUTES, getUrlWithBackToParam, PUBLIC_SCREENS_ROUTES};
880883
export default ROUTES;
881884

882885
// eslint-disable-next-line @typescript-eslint/no-explicit-any

src/libs/actions/Report.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ import {prepareDraftComment} from '@libs/DraftCommentUtils';
5757
import * as EmojiUtils from '@libs/EmojiUtils';
5858
import * as Environment from '@libs/Environment/Environment';
5959
import * as ErrorUtils from '@libs/ErrorUtils';
60+
import isPublicScreenRoute from '@libs/isPublicScreenRoute';
6061
import * as Localize from '@libs/Localize';
6162
import Log from '@libs/Log';
6263
import Navigation from '@libs/Navigation/Navigation';
@@ -2481,8 +2482,9 @@ function toggleEmojiReaction(
24812482

24822483
function openReportFromDeepLink(url: string, shouldNavigate = true) {
24832484
const reportID = ReportUtils.getReportIDFromLink(url);
2485+
const isAuthenticated = Session.hasAuthToken();
24842486

2485-
if (reportID && !Session.hasAuthToken()) {
2487+
if (reportID && !isAuthenticated) {
24862488
// 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
24872489
openReport(reportID, '', [], {}, '0', true);
24882490

@@ -2495,12 +2497,17 @@ function openReportFromDeepLink(url: string, shouldNavigate = true) {
24952497
Onyx.set(ONYXKEYS.IS_CHECKING_PUBLIC_ROOM, false);
24962498
}
24972499

2500+
const route = ReportUtils.getRouteFromLink(url);
2501+
2502+
// 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
2503+
if (!isAuthenticated && isPublicScreenRoute(route)) {
2504+
return;
2505+
}
2506+
24982507
// Navigate to the report after sign-in/sign-up.
24992508
InteractionManager.runAfterInteractions(() => {
25002509
Session.waitForUserSignIn().then(() => {
25012510
Navigation.waitForProtectedRoutes().then(() => {
2502-
const route = ReportUtils.getRouteFromLink(url);
2503-
25042511
if (route && Session.isAnonymousUser() && !Session.canAnonymousUserAccessRoute(route)) {
25052512
Session.signOutAndRedirectToSignIn(true);
25062513
return;

src/libs/isPublicScreenRoute.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {PUBLIC_SCREENS_ROUTES} from '@src/ROUTES';
2+
3+
export default function isPublicScreenRoute(route: string) {
4+
return Object.values(PUBLIC_SCREENS_ROUTES).some((screenRoute) => {
5+
const routeRegex = new RegExp(`^${screenRoute.replace(/:\w+/g, '\\w+')}$`);
6+
return routeRegex.test(route);
7+
});
8+
}

0 commit comments

Comments
 (0)