Clear session when auth fails

zio/stable
Paul Frazee 2022-11-17 12:33:59 -06:00
parent eae5ac839c
commit 0d70a09777
1 changed files with 8 additions and 1 deletions

View File

@ -18,7 +18,7 @@ export async function setupState() {
libapi.doPolyfill() libapi.doPolyfill()
const api = AtpApi.service(DEFAULT_SERVICE) const api = AtpApi.service(DEFAULT_SERVICE) as SessionServiceClient
rootStore = new RootStoreModel(api) rootStore = new RootStoreModel(api)
try { try {
data = (await storage.load(ROOT_STATE_STORAGE_KEY)) || {} data = (await storage.load(ROOT_STATE_STORAGE_KEY)) || {}
@ -28,6 +28,13 @@ export async function setupState() {
} }
await rootStore.session.setup() await rootStore.session.setup()
// @ts-ignore .on() is correct -prf
api.sessionManager.on('session', () => {
if (!api.sessionManager.session && rootStore.session.isAuthed) {
// reset session
rootStore.session.clear()
}
})
// track changes & save to storage // track changes & save to storage
autorun(() => { autorun(() => {