-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
LogOutPreviousUserPage.js
79 lines (69 loc) · 2.97 KB
/
LogOutPreviousUserPage.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useEffect} from 'react';
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';
const propTypes = {
/** The details about the account that the user is signing in with */
account: PropTypes.shape({
/** Whether the account data is loading */
isLoading: PropTypes.bool,
}),
/** The data about the current session which will be set once the user is authenticated and we return to this component as an AuthScreen */
session: PropTypes.shape({
/** The user's email for the current session */
email: PropTypes.string,
}),
};
const defaultProps = {
account: {
isLoading: false,
},
session: {
email: null,
},
};
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';
if (shouldForceLogin) {
const email = lodashGet(props, 'route.params.email', '');
const shortLivedAuthToken = lodashGet(props, 'route.params.shortLivedAuthToken', '');
Session.signInWithShortLivedAuthToken(email, shortLivedAuthToken);
}
const exitTo = lodashGet(props, 'route.params.exitTo', '');
if (exitTo && !props.account.isLoading && !isLoggingInAsNewUser) {
Navigation.isNavigationReady().then(() => {
Navigation.navigate(exitTo);
});
}
});
}, [props]);
return <FullScreenLoadingIndicator />;
}
LogOutPreviousUserPage.propTypes = propTypes;
LogOutPreviousUserPage.defaultProps = defaultProps;
LogOutPreviousUserPage.displayName = 'LogOutPreviousUserPage';
export default withOnyx({
account: {
key: ONYXKEYS.ACCOUNT,
},
session: {
key: ONYXKEYS.SESSION,
},
})(LogOutPreviousUserPage);