Skip to content
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
4 changes: 2 additions & 2 deletions src/libs/SessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import ONYXKEYS from '@src/ONYXKEYS';
/**
* Determine if the transitioning user is logging in as a new user.
*/
function isLoggingInAsNewUser(transitionURL: string, sessionEmail: string): boolean {
function isLoggingInAsNewUser(transitionURL?: string, sessionEmail?: string): boolean {
// The OldDot mobile app does not URL encode the parameters, but OldDot web
// does. We don't want to deploy OldDot mobile again, so as a work around we
// compare the session email to both the decoded and raw email from the transition link.
Expand All @@ -20,7 +20,7 @@ function isLoggingInAsNewUser(transitionURL: string, sessionEmail: string): bool
// If they do not match it might be due to encoding, so check the raw value
// Capture the un-encoded text in the email param
const emailParamRegex = /[?&]email=([^&]*)/g;
const matches = emailParamRegex.exec(transitionURL);
const matches = emailParamRegex.exec(transitionURL ?? '');
const linkedEmail = matches?.[1] ?? null;
return linkedEmail !== sessionEmail;
}
Expand Down
96 changes: 0 additions & 96 deletions src/pages/LogOutPreviousUserPage.js

This file was deleted.

60 changes: 60 additions & 0 deletions src/pages/LogOutPreviousUserPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useEffect} from 'react';
import {Linking} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import * as SessionUtils from '@libs/SessionUtils';
import type {AuthScreensParamList} from '@navigation/types';
import * as SessionActions from '@userActions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
import type SCREENS from '@src/SCREENS';
import type {Session} from '@src/types/onyx';

type LogOutPreviousUserPageOnyxProps = {
/** The data about the current session which will be set once the user is authenticated and we return to this component as an AuthScreen */
session: OnyxEntry<Session>;
};

type LogOutPreviousUserPageProps = LogOutPreviousUserPageOnyxProps & StackScreenProps<AuthScreensParamList, typeof SCREENS.TRANSITION_BETWEEN_APPS>;

// This page is responsible for handling transitions from OldDot. Specifically, it logs the current user
// out if the transition is for another user.
//
// This component should not do any other navigation as that handled in App.setUpPoliciesAndNavigate
function LogOutPreviousUserPage({session, route}: LogOutPreviousUserPageProps) {
useEffect(() => {
Linking.getInitialURL().then((transitionURL) => {
const sessionEmail = session?.email;
const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(transitionURL ?? undefined, sessionEmail);
Comment thread
neil-marcellini marked this conversation as resolved.
Resolved

if (isLoggingInAsNewUser) {
SessionActions.signOutAndRedirectToSignIn();
}

// We need to signin and fetch a new authToken, if a user was already authenticated in NewDot, and was redirected to OldDot
// and their authToken stored in Onyx becomes invalid.
// This workflow is triggered while setting up VBBA. User is redirected from NewDot to OldDot to set up 2FA, and then redirected back to NewDot
// On Enabling 2FA, authToken stored in Onyx becomes expired and hence we need to fetch new authToken
const shouldForceLogin = route.params.shouldForceLogin === 'true';
if (shouldForceLogin) {
const email = route.params.email ?? '';
const shortLivedAuthToken = route.params.shortLivedAuthToken ?? '';
SessionActions.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}
});

// We only want to run this effect once on mount (when the page first loads after transitioning from OldDot)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return <FullScreenLoadingIndicator />;
}

LogOutPreviousUserPage.displayName = 'LogOutPreviousUserPage';

export default withOnyx<LogOutPreviousUserPageProps, LogOutPreviousUserPageOnyxProps>({
session: {
key: ONYXKEYS.SESSION,
},
})(LogOutPreviousUserPage);