Skip to content

Commit

Permalink
Merge pull request #35827 from aswin-s/fix/issue-35745
Browse files Browse the repository at this point in the history
[CP Staging] fix: wait for navigation ready state before signing in

(cherry picked from commit e9f7b81)
  • Loading branch information
marcaaron authored and OSBotify committed Feb 5, 2024
1 parent 5f452c3 commit 7df3316
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/pages/ValidateLoginPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {withOnyx} from 'react-native-onyx';
import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Navigation from '@libs/Navigation/Navigation';
import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {ValidateLoginPageOnyxNativeProps, ValidateLoginPageProps} from './types';

Expand All @@ -13,16 +14,29 @@ function ValidateLoginPage({
session,
}: ValidateLoginPageProps<ValidateLoginPageOnyxNativeProps>) {
useEffect(() => {
if (session?.authToken) {
// If already signed in, do not show the validate code if not on web,
// because we don't want to block the user with the interstitial page.
Navigation.goBack();
} else {
Session.signInWithValidateCodeAndNavigate(Number(accountID), validateCode);
}
// Wait till navigation becomes available
Navigation.isNavigationReady().then(() => {
if (session?.authToken) {
// If already signed in, do not show the validate code if not on web,
// because we don't want to block the user with the interstitial page.
Navigation.goBack();
} else {
Session.signInWithValidateCodeAndNavigate(Number(accountID), validateCode);
}
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
if (session?.autoAuthState !== CONST.AUTO_AUTH_STATE.FAILED) {
return;
}
// Go back to initial route if validation fails
Navigation.isNavigationReady().then(() => {
Navigation.goBack();
});
}, [session?.autoAuthState]);

return <FullScreenLoadingIndicator />;
}

Expand Down

0 comments on commit 7df3316

Please sign in to comment.