diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 3aac19025d..f8b5b33a18 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -120,6 +120,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) { cancelPendingTask() dispatch({ type: 'logged-out', + accountDid: account.did, }) logEvent('account:loggedOut', {logContext}) addSessionDebugLog({type: 'method:end', method: 'logout'}) diff --git a/src/state/session/reducer.ts b/src/state/session/reducer.ts index 0a537b42c6..a7bf36779f 100644 --- a/src/state/session/reducer.ts +++ b/src/state/session/reducer.ts @@ -143,12 +143,20 @@ let reducer = (state: State, action: Action): State => { } } case 'logged-out': { + //Fetch the account ID that the user signed out from + const {accountDid} = action + + //Find the account for which the tokens need to be cleared + const loggedOutAccount = state.accounts.filter(a => a.did === accountDid) + + //Clear the tokens for the account that the user signed out from + loggedOutAccount.accessJwt = undefined + loggedOutAccount.refreshJwt = undefined + return { - accounts: state.accounts.map(a => ({ - ...a, - // Clear tokens for *every* account (this is a hard logout). - refreshJwt: undefined, - accessJwt: undefined, + //Return all the accounts. The other accounts remain unchanged, so the user will + //stay signed in on them. + accounts: state.accounts })), currentAgentState: createPublicAgentState(), needsPersist: true,