Skip to content

Commit

Permalink
Re-revert Expensify#13758
Browse files Browse the repository at this point in the history
  • Loading branch information
tgolen authored and bernhardoj committed Jan 16, 2023
1 parent 2c6f03b commit 7229212
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/libs/actions/SignInRedirect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@ import * as Localize from '../Localize';
import * as PersistedRequests from './PersistedRequests';
import NetworkConnection from '../NetworkConnection';

let currentActiveClients;
Onyx.connect({
key: ONYXKEYS.ACTIVE_CLIENTS,
callback: (val) => {
currentActiveClients = !val ? [] : val;
},
});

let currentPreferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: val => currentPreferredLocale = val,
});

let currentIsOffline;
let currentShouldForceOffline;
Onyx.connect({
Expand All @@ -37,10 +23,29 @@ Onyx.connect({
* @param {String} errorMessage
*/
function clearStorageAndRedirect(errorMessage) {
const activeClients = currentActiveClients;
const preferredLocale = currentPreferredLocale;
const isOffline = currentIsOffline;
const shouldForceOffline = currentShouldForceOffline;
// Under certain conditions, there are key-values we'd like to keep in storage even when a user is logged out.
// We pass these into the clear() method in order to avoid having to reset them on a delayed tick and getting
// flashes of unwanted default state.
const keysToPreserve = [];
keysToPreserve.push(ONYXKEYS.NVP_PREFERRED_LOCALE);
keysToPreserve.push(ONYXKEYS.ACTIVE_CLIENTS);

// After signing out, set ourselves as offline if we were offline before logging out and we are not forcing it.
// If we are forcing offline, ignore it while signed out, otherwise it would require a refresh because there's no way to toggle the switch to go back online while signed out.
if (currentIsOffline && !currentShouldForceOffline) {
keysToPreserve.push(ONYXKEYS.NETWORK);
}

Onyx.clear(keysToPreserve)
.then(() => {
if (!errorMessage) {
return;
}

// `Onyx.clear` reinitializes the Onyx instance with initial values so use `Onyx.merge` instead of `Onyx.set`
Onyx.merge(ONYXKEYS.SESSION, {errors: {[DateUtils.getMicroseconds()]: Localize.translateLocal(errorMessage)}});
});


// Clearing storage discards the authToken. This causes a redirect to the SignIn screen
Onyx.clear()
Expand Down

0 comments on commit 7229212

Please sign in to comment.