@@ -12,6 +12,7 @@ import {clearAllPolicies} from './Policy/Policy';
1212let currentShouldForceOffline : boolean | undefined ;
1313let currentIsUsingImportedState : boolean | undefined ;
1414let currentSessionAuthToken : string | undefined ;
15+ let currentSessionEmail : string | undefined ;
1516let currentCredentialsValidateCode : string | undefined ;
1617
1718Onyx . connectWithoutView ( {
@@ -32,6 +33,7 @@ Onyx.connectWithoutView({
3233 key : ONYXKEYS . SESSION ,
3334 callback : ( session ) => {
3435 currentSessionAuthToken = session ?. authToken ;
36+ currentSessionEmail = session ?. email ;
3537 } ,
3638} ) ;
3739
@@ -42,7 +44,7 @@ Onyx.connectWithoutView({
4244 } ,
4345} ) ;
4446
45- function clearStorageAndRedirect ( errorMessage ?: string ) : Promise < void > {
47+ function clearStorageAndRedirect ( errorMessage ?: string , isSAMLReauthentication ?: boolean ) : Promise < void > {
4648 // Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out.
4749 // We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting
4850 // flashes of unwanted default state.
@@ -79,6 +81,14 @@ function clearStorageAndRedirect(errorMessage?: string): Promise<void> {
7981 keysToPreserve . push ( ONYXKEYS . ACCOUNT ) ;
8082 }
8183
84+ // Mark the account as loading and set the login in credentials to trigger the `SAML_SIGN_IN` transition
85+ if ( isSAMLReauthentication ) {
86+ keysToPreserve . push ( ONYXKEYS . CREDENTIALS ) ;
87+ keysToPreserve . push ( ONYXKEYS . ACCOUNT ) ;
88+ Onyx . merge ( ONYXKEYS . CREDENTIALS , { login : currentSessionEmail , autoGeneratedLogin : null , autoGeneratedPassword : null } ) ;
89+ Onyx . merge ( ONYXKEYS . ACCOUNT , { isLoading : true } ) ;
90+ }
91+
8292 return Onyx . clear ( keysToPreserve ) . then ( ( ) => {
8393 if ( CONFIG . IS_HYBRID_APP ) {
8494 resetSignInFlow ( ) ;
@@ -108,10 +118,11 @@ function clearStorageAndRedirect(errorMessage?: string): Promise<void> {
108118 *
109119 * Normally this method would live in Session.js, but that would cause a circular dependency with Network.js.
110120 *
111- * @param [errorMessage] error message to be displayed on the sign in page
121+ * @param errorMessage Error message to be displayed on the sign in page
122+ * @param isSAMLReauthentication Whether the redirection was triggered by reauthentication for SAML required account
112123 */
113- function redirectToSignIn ( errorMessage ?: string ) : Promise < void > {
114- return clearStorageAndRedirect ( errorMessage ) . then ( ( ) => {
124+ function redirectToSignIn ( errorMessage ?: string , isSAMLReauthentication ?: boolean ) : Promise < void > {
125+ return clearStorageAndRedirect ( errorMessage , isSAMLReauthentication ) . then ( ( ) => {
115126 clearSessionStorage ( ) ;
116127 } ) ;
117128}
0 commit comments