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 repeated calls to SignInWithShortLivedAuthToken #34305

Merged
merged 7 commits into from
Jan 12, 2024
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/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()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to waiting for the navigation to be "ready", waitForProtectedRoutes waits for one of our authenticated routes (like the LHN or a report) to be rendered.

Atm isNavigationReady is a bit of a hack (it gets triggered here) and doesn't work very well in testing , but this works consistently.

.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
Loading