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: 3 additions & 1 deletion src/libs/actions/WelcomeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Added this otherwise we would pop open the create menu in some contexts. I guess the top route is not always "workspace" and sometimes still the LoginWithShortLivedToken page.

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.
Expand Down
35 changes: 11 additions & 24 deletions src/pages/LogInWithShortLivedTokenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Comment thread
roryabraham marked this conversation as resolved.
}

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/<ID>/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/<accountID>/<email>/<authToken>/workspace/<policyID>/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/<accountID>/<email>/<authToken>/workspace/<policyID>/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);
}
Expand All @@ -105,6 +97,7 @@ class LogInWithShortLivedTokenPage extends Component {
return false;
}

Log.info('[LoginWithShortLivedTokenPage] Different user signed in - signing out');
Session.signOutAndRedirectToSignIn();
return true;
}
Expand All @@ -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);