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

Fix can't login using magic link when signed in as anonymous user #37952

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 6 additions & 5 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ function signInWithValidateCodeAndNavigate(accountID: number, validateCode: stri
if (exitTo) {
handleExitToNavigation(exitTo);
} else {
Navigation.navigate(ROUTES.HOME);
Navigation.goBack();
}
}

Expand All @@ -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;
Expand All @@ -948,9 +948,10 @@ 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];
const isMagicLink = CONST.REGEX.ROUTES.VALIDATE_LOGIN.test(`/${route}`);

if ((routesCanAccessByAnonymousUser as string[]).includes(routeRemovedReportId)) {
if ((routesAccessibleByAnonymousUser as string[]).includes(routeRemovedReportId) || isMagicLink) {
return true;
}
return false;
Expand Down Expand Up @@ -986,7 +987,7 @@ export {
toggleTwoFactorAuth,
validateTwoFactorAuth,
waitForUserSignIn,
canAccessRouteByAnonymousUser,
canAnonymousUserAccessRoute,
signInWithSupportAuthToken,
isSupportAuthToken,
hasStashedSession,
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ValidateLoginPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/ValidateLoginPage/index.website.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function ValidateLoginPage({
}: ValidateLoginPageProps<ValidateLoginPageOnyxProps>) {
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;

Expand Down
Loading