Fix clearing all data on signout

This commit is contained in:
Mo Bitar
2018-07-10 10:37:47 -05:00
parent 098de53d4c
commit af1fdf715e
3 changed files with 13 additions and 1 deletions

View File

@@ -12,6 +12,7 @@ import KeysManager from './lib/keysManager'
import Auth from './lib/sfjs/authManager'
import ModelManager from './lib/sfjs/modelManager'
import Sync from './lib/sfjs/syncManager'
import Storage from './lib/sfjs/storageManager'
import ReviewManager from './lib/reviewManager';
import GlobalStyles from "./Styles"
import Icons from "./Icons"
@@ -78,6 +79,7 @@ export default class App {
this.signoutObserver = Auth.get().addEventHandler((event) => {
if(event == SFAuthManager.DidSignOutEvent) {
this.optionsState.reset();
Storage.get().clearAllModels();
KeysManager.get().clearAccountKeysAndData();
ModelManager.get().handleSignout();
Sync.get().handleSignout();

View File

@@ -125,10 +125,15 @@ export default class KeysManager {
this.loadLocalStateFromKeys(null);
this.accountAuthParams = null;
this.user = null;
Storage.get().setItem(FirstRunKey, "false")
Storage.get().setItem(FirstRunKey, "false");
}.bind(this));
}
/*
We need to register local storage keys, so that when we want to sign out, we don't accidentally
clear internal keys, like first_run. (If you accidentally delete the first_run key when you sign out,
then the next time you sign in and refresh, it will treat it as a new run, and delete all data.)
*/
registerAccountRelatedStorageKeys(storageKeys) {
this.accountRelatedStorageKeys = _.uniq(this.accountRelatedStorageKeys.concat(storageKeys));
}

View File

@@ -37,6 +37,11 @@ export default class Auth extends SFAuthManager {
return !keys.jwt;
}
async signout(clearAllData) {
// DONT clear all data. We will do this ourselves manually, as we need to preserve certain data keys.
super.signout(false);
}
async getAuthParams() {
return KeysManager.get().activeAuthParams();
}