Skip to content

Commit

Permalink
Merge pull request Expensify#34305 from Expensify/arosiclair-sign-in-…
Browse files Browse the repository at this point in the history
…loop

Fix repeated calls to SignInWithShortLivedAuthToken
  • Loading branch information
grgia authored Jan 12, 2024
2 parents 8ede904 + 999a946 commit bb8b976
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/libs/actions/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ function setUpPoliciesAndNavigate(session: OnyxEntry<OnyxTypes.Session>) {
return;
}
if (!isLoggingInAsNewUser && exitTo) {
Navigation.isNavigationReady()
Navigation.waitForProtectedRoutes()
.then(() => {
// We must call goBack() to remove the /transition route from history
Navigation.goBack(ROUTES.HOME);
Expand Down
21 changes: 8 additions & 13 deletions src/pages/LogOutPreviousUserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {Linking} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import * as SessionUtils from '@libs/SessionUtils';
import Navigation from '@navigation/Navigation';
import * as Session from '@userActions/Session';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';

const propTypes = {
/** The details about the account that the user is signing in with */
Expand All @@ -33,6 +31,10 @@ const defaultProps = {
},
};

// 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(props) {
useEffect(() => {
Linking.getInitialURL().then((transitionURL) => {
Expand All @@ -53,18 +55,11 @@ function LogOutPreviousUserPage(props) {
const shortLivedAuthToken = lodashGet(props, 'route.params.shortLivedAuthToken', '');
Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}

const exitTo = lodashGet(props, 'route.params.exitTo', '');
// We don't want to navigate to the exitTo route when creating a new workspace from a deep link,
// because we already handle creating the optimistic policy and navigating to it in App.setUpPoliciesAndNavigate,
// which is already called when AuthScreens mounts.
if (exitTo && exitTo !== ROUTES.WORKSPACE_NEW && !props.account.isLoading && !isLoggingInAsNewUser) {
Navigation.isNavigationReady().then(() => {
Navigation.navigate(exitTo);
});
}
});
}, [props]);

// 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 />;
}
Expand Down

0 comments on commit bb8b976

Please sign in to comment.