diff --git a/src/libs/actions/SignInRedirect.ts b/src/libs/actions/SignInRedirect.ts index da39079dc512..3e28fdcfb2f2 100644 --- a/src/libs/actions/SignInRedirect.ts +++ b/src/libs/actions/SignInRedirect.ts @@ -34,11 +34,20 @@ function clearStorageAndRedirect(errorMessage?: string): Promise { keysToPreserve.push(ONYXKEYS.NETWORK); } + // Preserve troubleshooting flags + keysToPreserve.push(ONYXKEYS.APP_PROFILING_IN_PROGRESS); + keysToPreserve.push(ONYXKEYS.SHOULD_STORE_LOGS); + keysToPreserve.push(ONYXKEYS.SHOULD_MASK_ONYX_STATE); + + // Preserve account settings (staging server, debug mode, etc.) across logout + keysToPreserve.push(ONYXKEYS.ACCOUNT); + return Onyx.clear(keysToPreserve).then(() => { if (CONFIG.IS_HYBRID_APP) { resetSignInFlow(); } clearAllPolicies(); + if (!errorMessage) { return; } diff --git a/src/pages/signin/SignInPage.tsx b/src/pages/signin/SignInPage.tsx index 8ad0b93fc44e..e074f2f80275 100644 --- a/src/pages/signin/SignInPage.tsx +++ b/src/pages/signin/SignInPage.tsx @@ -108,7 +108,8 @@ function getRenderOptions({ // SAML required users may reload the login page after having already entered their login details, in which // case we want to clear their sign in data so they don't end up in an infinite loop redirecting back to their // SSO provider's login page - if (hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { + // Don't clear if we don't have account data - this prevents clearing during app resets when state is inconsistent + if (hasAccount && hasLogin && isSAMLRequired && !shouldInitiateSAMLLogin && !hasInitiatedSAMLLogin && !account.isLoading) { clearSignInData(); }