diff --git a/src/libs/actions/WelcomeActions.js b/src/libs/actions/WelcomeActions.js index c3b6c7f18d1f..f1db29c89f1e 100644 --- a/src/libs/actions/WelcomeActions.js +++ b/src/libs/actions/WelcomeActions.js @@ -68,7 +68,9 @@ function show({routes, toggleCreateMenu}) { // If we are rendering the SidebarScreen at the same time as a workspace route that means we've already created a workspace via workspace/new and should not open the global // create menu right now. const topRouteName = lodashGet(_.last(routes), 'name', ''); - const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace'); + const loginWithShortLivedTokenRoute = _.find(routes, route => route.name === 'LogInWithShortLivedToken'); + const exitingToWorkspaceRoute = lodashGet(loginWithShortLivedTokenRoute, 'params.exitTo', '') === 'workspace/new'; + const isDisplayingWorkspaceRoute = topRouteName.toLowerCase().includes('workspace') || exitingToWorkspaceRoute; // It's also possible that we already have a workspace policy. In either case we will not toggle the menu but do still want to set the NVP in this case // since the user does not need to create a workspace. diff --git a/src/pages/LogInWithShortLivedTokenPage.js b/src/pages/LogInWithShortLivedTokenPage.js index acd8c659104b..5e091ead6f83 100644 --- a/src/pages/LogInWithShortLivedTokenPage.js +++ b/src/pages/LogInWithShortLivedTokenPage.js @@ -7,6 +7,7 @@ import ONYXKEYS from '../ONYXKEYS'; import * as Session from '../libs/actions/Session'; import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator'; import Navigation from '../libs/Navigation/Navigation'; +import Log from '../libs/Log'; const propTypes = { /** The parameters needed to authenticate with a short lived token are in the URL */ @@ -49,44 +50,35 @@ const defaultProps = { class LogInWithShortLivedTokenPage extends Component { componentDidMount() { - const accountID = parseInt(lodashGet(this.props.route.params, 'accountID', ''), 10); + const accountID = lodashGet(this.props.route.params, 'accountID', ''); const email = lodashGet(this.props.route.params, 'email', ''); const shortLivedToken = lodashGet(this.props.route.params, 'shortLivedToken', ''); const isUserSignedIn = this.props.session && this.props.session.authToken; if (!isUserSignedIn) { + Log.info('[LoginWithShortLivedTokenPage] User not signed in - signing in with short lived token'); Session.signInWithShortLivedToken(accountID, email, shortLivedToken); return; } - this.signOutIfNeeded(email); - } - - componentDidUpdate() { - if (!lodashGet(this.props, 'session.authToken', null)) { + if (this.signOutIfNeeded(email)) { return; } - const email = lodashGet(this.props.route.params, 'email', ''); + Log.info('[LoginWithShortLivedTokenPage] User is signed in'); // 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 (this.signOutIfNeeded(email)) { - return; - } - 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. But there is no current - // modal you say? I know, it confuses me too. 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. + // 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); } @@ -105,6 +97,7 @@ class LogInWithShortLivedTokenPage extends Component { return false; } + Log.info('[LoginWithShortLivedTokenPage] Different user signed in - signing out'); Session.signOutAndRedirectToSignIn(); return true; } @@ -121,10 +114,4 @@ export default withOnyx({ session: { key: ONYXKEYS.SESSION, }, - - // We need to subscribe to the betas so that componentDidUpdate will run, - // causing us to exit to the proper page. - betas: { - key: ONYXKEYS.BETAS, - }, })(LogInWithShortLivedTokenPage);