diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.js b/src/libs/Navigation/AppNavigator/AuthScreens.js index 678fd9f0326c..b63e0b8dd29f 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.js +++ b/src/libs/Navigation/AppNavigator/AuthScreens.js @@ -132,25 +132,12 @@ class AuthScreens extends React.Component { // Load policies, maybe creating a new policy first. Linking.getInitialURL() .then((url) => { - if (!url) { - return; - } - const path = new URL(url).pathname; - const params = new URLSearchParams(url); - const exitTo = params.get('exitTo'); - const email = params.get('email'); - const isLoggingInAsNewUser = this.props.session && this.props.session.email !== email; - const shouldCreateFreePolicy = !isLoggingInAsNewUser - && Str.startsWith(path, Str.normalizeUrl(ROUTES.TRANSITION)) - && exitTo === ROUTES.WORKSPACE_NEW; - if (shouldCreateFreePolicy) { + if (this.shouldCreateFreePolicy(url)) { Policy.createAndGetPolicyList(); return; } + Policy.getPolicyList(); - if (!isLoggingInAsNewUser && exitTo) { - this.navigateToExitRoute(exitTo); - } }); // Refresh the personal details, timezone and betas every 30 minutes @@ -198,17 +185,22 @@ class AuthScreens extends React.Component { } /** - * Navigate to the transition exit route - * - * @param {String} exitTo + * @param {String} [url] + * @returns {Boolean} */ - navigateToExitRoute(exitTo) { - // In order to navigate to a modal, we first have to dismiss the current modal. Without dismissing the current modal, if the user cancels out of the workspace modal, - // then they will be routed back to /transition////workspace//card and we don't want that. We want them to go back to `/` - // and by calling dismissModal(), the /transition/... route is removed from history so the user will get taken to `/` if they cancel out of the new workspace modal. - Log.info('[AuthScreens] Dismissing LogOutOldUserPage and navigating to the transition exit route'); - Navigation.dismissModal(); - Navigation.navigate(exitTo); + shouldCreateFreePolicy(url = '') { + if (!url) { + return false; + } + + const path = new URL(url).pathname; + const params = new URLSearchParams(url); + const exitTo = params.get('exitTo'); + const email = params.get('email'); + const isLoggingInAsNewUser = !_.isNull(this.props.session.email) && (email !== this.props.session.email); + return !isLoggingInAsNewUser + && Str.startsWith(path, Str.normalizeUrl(ROUTES.TRANSITION)) + && exitTo === ROUTES.WORKSPACE_NEW; } render() { diff --git a/src/pages/LogOutOldUserPage.js b/src/pages/LogOutOldUserPage.js index 0189df47f935..a031c73edce0 100644 --- a/src/pages/LogOutOldUserPage.js +++ b/src/pages/LogOutOldUserPage.js @@ -6,6 +6,8 @@ import ONYXKEYS from '../ONYXKEYS'; import * as Session from '../libs/actions/Session'; import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; import Log from '../libs/Log'; +import Navigation from '../libs/Navigation/Navigation'; +import ROUTES from '../ROUTES'; const propTypes = { /** The parameters needed to authenticate with a short lived token are in the URL */ @@ -52,7 +54,23 @@ class LogOutOldUserPage extends Component { if (this.props.session && this.props.session.email !== email) { Log.info('[LogOutOldUserPage] Different user signed in - signing out'); Session.signOutAndRedirectToSignIn(); + return; } + + // exitTo is URI encoded because it could contain a variable number of slashes (i.e. "workspace/new" vs "workspace//card") + const exitTo = decodeURIComponent(lodashGet(this.props.route.params, 'exitTo', '')); + if (exitTo === ROUTES.WORKSPACE_NEW) { + // New workspace creation is handled in AuthScreens, not in its own screen + Log.info('[LoginWithShortLivedTokenPage] exitTo is workspace/new - handling new workspace creation in AuthScreens'); + return; + } + + // In order to navigate to a modal, we first have to dismiss the current modal. Without dismissing the current modal, if the user cancels out of the workspace modal, + // then they will be routed back to /transition////workspace//card and we don't want that. We want them to go back to `/` + // and by calling dismissModal(), the /transition/... route is removed from history so the user will get taken to `/` if they cancel out of the new workspace modal. + Log.info('[LoginWithShortLivedTokenPage] Dismissing LoginWithShortLivedTokenPage and navigating to exitTo'); + Navigation.dismissModal(); + Navigation.navigate(exitTo); } render() {