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: fix transitioning issue from old dot #28984

Merged
12 changes: 12 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import {View} from 'react-native';
import Str from "expensify-common/lib/str";
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import CONST from '../../../CONST';
import compose from '../../compose';
Expand Down Expand Up @@ -35,6 +36,7 @@ import * as SessionUtils from '../../SessionUtils';
import NotFoundPage from '../../../pages/ErrorPage/NotFoundPage';
import getRootNavigatorScreenOptions from './getRootNavigatorScreenOptions';
import DemoSetupPage from '../../../pages/DemoSetupPage';
import getCurrentUrl from "../currentUrl";

let timezone;
let currentAccountID;
Expand Down Expand Up @@ -137,6 +139,16 @@ class AuthScreens extends React.Component {
}

componentDidMount() {
const currentUrl = getCurrentUrl();
const url = new URL(currentUrl);
const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(currentUrl, this.props.session.email);
// Sign out the current user if we're transitioning with a different user
const isTransitioning = Str.startsWith(url.pathname, Str.normalizeUrl(ROUTES.TRANSITION_BETWEEN_APPS));
if (isLoggingInAsNewUser && isTransitioning) {
Session.signOutAndRedirectToSignIn();
return;
}

NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => {
if (isLoadingApp) {
Expand Down
3 changes: 0 additions & 3 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ function setUpPoliciesAndNavigate(session, shouldNavigateToAdminChat) {

// Sign out the current user if we're transitioning with a different user
const isTransitioning = Str.startsWith(url.pathname, Str.normalizeUrl(ROUTES.TRANSITION_BETWEEN_APPS));
if (isLoggingInAsNewUser && isTransitioning) {
Session.signOut();
}

const shouldCreateFreePolicy = !isLoggingInAsNewUser && isTransitioning && exitTo === ROUTES.WORKSPACE_NEW;
if (shouldCreateFreePolicy) {
Expand Down
33 changes: 9 additions & 24 deletions src/pages/LogOutPreviousUserPage.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import React, {useEffect} from 'react';
import {Linking} from 'react-native';
import React, { useEffect } from 'react';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import { withOnyx } from 'react-native-onyx';
import ONYXKEYS from '../ONYXKEYS';
import * as Session from '../libs/actions/Session';
import FullScreenLoadingIndicator from '../components/FullscreenLoadingIndicator';
import * as SessionUtils from '../libs/SessionUtils';

const propTypes = {
/** The data about the current session which will be set once the user is authenticated and we return to this component as an AuthScreen */
Expand All @@ -25,31 +23,18 @@ const defaultProps = {
function LogOutPreviousUserPage(props) {
useEffect(
() => {
Linking.getInitialURL().then((transitionURL) => {
const sessionEmail = props.session.email;
const isLoggingInAsNewUser = SessionUtils.isLoggingInAsNewUser(transitionURL, sessionEmail);

if (isLoggingInAsNewUser) {
Session.signOutAndRedirectToSignIn();
}

// We need to signin and fetch a new authToken, if a user was already authenticated in NewDot, and was redirected to OldDot
// and their authToken stored in Onyx becomes invalid.
// This workflow is triggered while setting up VBBA. User is redirected from NewDot to OldDot to set up 2FA, and then redirected back to NewDot
// On Enabling 2FA, authToken stored in Onyx becomes expired and hence we need to fetch new authToken
const shouldForceLogin = lodashGet(props, 'route.params.shouldForceLogin', '') === 'true';
koko57 marked this conversation as resolved.
Show resolved Hide resolved
if (shouldForceLogin) {
const email = lodashGet(props, 'route.params.email', '');
const shortLivedAuthToken = lodashGet(props, 'route.params.shortLivedAuthToken', '');
Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}
});
const shouldForceLogin = lodashGet(props, 'route.params.shouldForceLogin', '') === 'true';
if (shouldForceLogin) {
const email = lodashGet(props, 'route.params.email', '');
const shortLivedAuthToken = lodashGet(props, 'route.params.shortLivedAuthToken', '');
Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[],
);

return <FullScreenLoadingIndicator />;
return <FullScreenLoadingIndicator/>;
}

LogOutPreviousUserPage.propTypes = propTypes;
Expand Down
Loading