fix: Auth persistence to localStorage (#3078)

* fix: user, team, and policies should be persisted to localStorage for faster boot

* capture instead of ignore errors
This commit is contained in:
Tom Moor
2022-02-08 21:14:15 -08:00
committed by GitHub
parent aa09dc39fb
commit 156b47b1b5
2 changed files with 35 additions and 10 deletions

View File

@@ -68,19 +68,21 @@ export default class AuthStore {
try {
data = JSON.parse(localStorage.getItem(AUTH_STORE) || "{}");
} catch (_) {
// no-op Safari private mode
} catch (err) {
Sentry.captureException(err);
}
this.rehydrate(data);
// persists this entire store to localstorage whenever any keys are changed
autorun(() => {
try {
localStorage.setItem(AUTH_STORE, this.asJson);
} catch (_) {
// no-op Safari private mode
} catch (err) {
Sentry.captureException(err);
}
});
// listen to the localstorage value changing in other tabs to react to
// signin/signout events in other tabs and follow suite.
window.addEventListener("storage", (event) => {