Skip to content

Commit

Permalink
Merge pull request #37952 from bernhardoj/fix/36812-cant-use-magic-li…
Browse files Browse the repository at this point in the history
…nk-to-log-in

Fix can't login using magic link when signed in as anonymous user
  • Loading branch information
flodnv authored Mar 8, 2024
2 parents 69b2c87 + 51f0e94 commit f98a06c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
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

0 comments on commit f98a06c

Please sign in to comment.