Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't navigate to public screen deep link after sign in #42130

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
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 Log from '@libs/Log';
import * as LoginUtils from '@libs/LoginUtils';
import Navigation, {navigationRef} from '@libs/Navigation/Navigation';
Expand Down Expand Up @@ -2460,8 +2461,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);

Expand All @@ -2474,12 +2476,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;
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);
});
}
Loading