Skip to content

Commit

Permalink
Clear storage immediately on sign out
Browse files Browse the repository at this point in the history
Waiting for `set` to complete gives enough time for other connections (triggered
by the authToken change) to be initiated with cached data
This causes a bug where the SignIn component does not have correct state
  • Loading branch information
kidroca committed Aug 12, 2021
1 parent daf0025 commit 72bf6c0
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/libs/actions/SignInRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,18 @@ function redirectToSignIn(errorMessage) {
const activeClients = currentActiveClients;
const preferredLocale = currentPreferredLocale;

// We must set the authToken to null so we can navigate to "signin" it's not possible to navigate to the route as
// it only exists when the authToken is null.
Onyx.set(ONYXKEYS.SESSION, {authToken: null})
// Clearing storage discards the authToken. This causes a redirect to the SignIn screen
Onyx.clear()
.then(() => {
Onyx.clear().then(() => {
if (preferredLocale) {
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
}
if (errorMessage) {
Onyx.set(ONYXKEYS.SESSION, {error: errorMessage});
}
if (activeClients && activeClients.length > 0) {
Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
}
});
if (preferredLocale) {
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
}
if (errorMessage) {
Onyx.set(ONYXKEYS.SESSION, {error: errorMessage});
}
if (activeClients && activeClients.length > 0) {
Onyx.set(ONYXKEYS.ACTIVE_CLIENTS, activeClients);
}
});
}

Expand Down

0 comments on commit 72bf6c0

Please sign in to comment.