From 341e04071d97e881dede4ff58c809cb7bef966e6 Mon Sep 17 00:00:00 2001 From: hailey Date: Thu, 27 Aug 2026 23:52:23 +0000 Subject: [PATCH] Honor remote logout during session refresh --- src/state/session/__tests__/session-test.ts | 35 +++++++++++++++++++++ src/state/session/reducer.ts | 2 +- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/state/session/__tests__/session-test.ts b/src/state/session/__tests__/session-test.ts index 7a4ea0d4ff..0717fba4b0 100644 --- a/src/state/session/__tests__/session-test.ts +++ b/src/state/session/__tests__/session-test.ts @@ -1855,6 +1855,41 @@ describe('session', () => { expect(rebased.accounts).toEqual([fresh]) }) + it('honors a remote logout over a concurrent local refresh', () => { + const stale = makeAccount('https://alice.com', { + active: true, + did: 'alice-did', + handle: 'alice.test', + accessJwt: 'alice-access-jwt-1', + refreshJwt: 'alice-refresh-jwt-1', + }) + const refreshed = { + ...stale, + accessJwt: 'alice-access-jwt-2', + refreshJwt: 'alice-refresh-jwt-2', + } + const loggedOut = { + ...stale, + accessJwt: undefined, + refreshJwt: undefined, + } + + const rebased = rebasePersistedSession( + snapshot([loggedOut]), + snapshot([refreshed], 'alice-did'), + { + type: 'received-session-event', + bundle: makeBundle('https://alice.com'), + accountDid: 'alice-did', + refreshedAccount: refreshed, + sessionEvent: 'update', + }, + ) + + expect(rebased.accounts).toEqual([loggedOut]) + expect(rebased.currentAccount).toBeUndefined() + }) + it('preserves a concurrent newer generation instead of clearing it on expiry', () => { const dying = makeAccount('https://alice.com', { active: true, diff --git a/src/state/session/reducer.ts b/src/state/session/reducer.ts index 03bd294fb2..deb7c60325 100644 --- a/src/state/session/reducer.ts +++ b/src/state/session/reducer.ts @@ -210,10 +210,10 @@ function selectCurrentDid({ return desiredCurrentDid case 'received-session-event': if ( - action.sessionEvent === 'expired' && action.accountDid !== undefined && preservedNewerTokenDids.has(action.accountDid) ) { + /* The latest tokens also own account selection after a conflict. */ return latestCurrentDid } return action.sessionEvent === 'expired'