From e69fbc9ef6f6ce21edfc47d8276982bd24d18f09 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Thu, 2 May 2024 22:55:18 +0100 Subject: [PATCH] [Session] Remove expired param from upsertAccount --- src/state/session/index.tsx | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 064fd05976..ec057afc16 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -70,11 +70,11 @@ export function Provider({children}: React.PropsWithChildren<{}>) { }) const upsertAccount = React.useCallback( - (account: SessionAccount, expired = false) => { + (account: SessionAccount) => { setState(s => { return { accounts: [account, ...s.accounts.filter(a => a.did !== account.did)], - currentAccountDid: expired ? undefined : account.did, + currentAccountDid: account.did, needsPersist: true, } }) @@ -133,12 +133,6 @@ export function Provider({children}: React.PropsWithChildren<{}>) { event, deactivated: refreshedAccount.deactivated, }) - - if (expired) { - logger.warn(`session: expired`) - emitSessionDropped() - } - /* * If the session expired, or it was successfully created/updated, we want * to update/persist the data. @@ -149,7 +143,18 @@ export function Provider({children}: React.PropsWithChildren<{}>) { * to persist this data and wipe their tokens, effectively logging them * out. */ - upsertAccount(refreshedAccount, expired) + upsertAccount(refreshedAccount) + + if (expired) { + logger.warn(`session: expired`) + emitSessionDropped() + setState(s => ({ + accounts: s.accounts, + currentAccountDid: undefined, + needsPersist: true, + })) + // TODO: Should this reset the agent too? + } }, [clearCurrentAccount, upsertAccount], )