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

Sign in, out, or navigate on transition mount #8257

Merged
merged 14 commits into from
Mar 23, 2022
Merged
1 change: 1 addition & 0 deletions src/ONYXKEYS.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export default {
// Information about the current session (authToken, accountID, email, loading, error)
SESSION: 'session',
BETAS: 'betas',
IS_LOADING_BETAS: 'isLoadingBetas',

// NVP keys
// Contains the user's payPalMe address
Expand Down
6 changes: 5 additions & 1 deletion src/libs/Growl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ import CONST from '../CONST';
const growlRef = React.createRef();

/**
* Show the growl notification
* Show the growl notification. If the ref is not available, retry until it is.
*
* @param {String} bodyText
* @param {String} type
* @param {Number} [duration]
*/
function show(bodyText, type, duration = CONST.GROWL.DURATION) {
if (!growlRef.current) {
setTimeout(() => show(bodyText, type, duration), 100);
return;
}
growlRef.current.show(bodyText, type, duration);
}

Expand Down
9 changes: 8 additions & 1 deletion src/libs/Navigation/AppNavigator/MainDrawerNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@ const propTypes = {

/** Beta features list */
betas: PropTypes.arrayOf(PropTypes.string),

/** Are the betas currently loading from the api? */
isLoadingBetas: PropTypes.bool,
};

const defaultProps = {
reports: {},
betas: [],
isLoadingBetas: true,
};

/**
Expand All @@ -48,7 +52,7 @@ const MainDrawerNavigator = (props) => {
const initialParams = getInitialReportScreenParams(props.reports, !Permissions.canUseDefaultRooms(props.betas));

// Wait until reports are fetched and there is a reportID in initialParams
if (!initialParams.reportID) {
if (!initialParams.reportID || props.isLoadingBetas) {
return <FullScreenLoadingIndicator />;
}

Expand Down Expand Up @@ -81,5 +85,8 @@ export default withOnyx({
betas: {
key: ONYXKEYS.BETAS,
},
isLoadingBetas: {
key: ONYXKEYS.IS_LOADING_BETAS,
},
})(MainDrawerNavigator);
export {getInitialReportScreenParams};
6 changes: 4 additions & 2 deletions src/libs/actions/Session/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,10 @@ function fetchAccountDetails(login) {
*
* @param {String} authToken
* @param {String} email
* @param {Boolean} shouldProcessImmediately
* @return {Promise}
*/
function createTemporaryLogin(authToken, email) {
function createTemporaryLogin(authToken, email, shouldProcessImmediately = true) {
const autoGeneratedLogin = Str.guid('expensify.cash-');
const autoGeneratedPassword = Str.guid();

Expand All @@ -188,6 +189,7 @@ function createTemporaryLogin(authToken, email) {
partnerUserSecret: autoGeneratedPassword,
shouldRetry: false,
forceNetworkRequest: true,
shouldProcessImmediately,
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here - I'm having trouble seeing how this is connected to the transition stuff.

Copy link
Contributor

Choose a reason for hiding this comment

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

Removed this code and it doesn't seem to impact anything.

email,
includeEncryptedAuthToken: true,
})
Expand Down Expand Up @@ -268,7 +270,7 @@ function signIn(password, twoFactorAuthCode) {
function signInWithShortLivedToken(accountID, email, shortLivedToken) {
Onyx.merge(ONYXKEYS.ACCOUNT, {...CONST.DEFAULT_ACCOUNT_DATA, loading: true});

createTemporaryLogin(shortLivedToken, email).then((response) => {
createTemporaryLogin(shortLivedToken, email, false).then((response) => {
Onyx.merge(ONYXKEYS.SESSION, {
accountID,
email,
Expand Down
2 changes: 2 additions & 0 deletions src/libs/actions/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ function closeAccount(message) {
}

function getBetas() {
Onyx.set(ONYXKEYS.IS_LOADING_BETAS, true);
API.User_GetBetas().then((response) => {
if (response.jsonCode !== 200) {
return;
}

Onyx.set(ONYXKEYS.BETAS, response.betas);
Onyx.set(ONYXKEYS.IS_LOADING_BETAS, false);
});
}

Expand Down
20 changes: 1 addition & 19 deletions src/pages/LogInWithShortLivedTokenPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,12 @@ class LogInWithShortLivedTokenPage extends Component {
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', '');

// 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
return;
Expand Down Expand Up @@ -121,10 +109,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);