Handle empty current logout state

This commit is contained in:
hailey
2026-08-27 23:50:03 +00:00
parent 7d6518cd49
commit 1ed2c757dc
2 changed files with 28 additions and 6 deletions
+25 -1
View File
@@ -1902,13 +1902,37 @@ describe('session', () => {
const rebased = rebasePersistedSession(
snapshot([fresh], 'alice-did'),
snapshot([loggedOut]),
{type: 'logged-out-current-account'},
{type: 'logged-out-current-account', accountDid: 'alice-did'},
)
expect(rebased.accounts).toEqual([loggedOut])
expect(rebased.currentAccount).toBeUndefined()
})
it('keeps latest tokens when no current account is available to log out', () => {
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 fresh = {
...stale,
accessJwt: 'alice-access-jwt-2',
refreshJwt: 'alice-refresh-jwt-2',
}
const rebased = rebasePersistedSession(
snapshot([fresh], 'alice-did'),
snapshot([stale]),
{type: 'logged-out-current-account'},
)
expect(rebased.accounts).toEqual([fresh])
expect(rebased.currentAccount).toBeUndefined()
})
it('clears only the explicitly logged-out account', () => {
const alice = makeAccount('https://alice.com', {
active: true,
+3 -5
View File
@@ -164,9 +164,7 @@ function getTokenWriteMode(
): 'replace' | 'clear' | 'keep-latest' {
switch (action.type) {
case 'logged-out-current-account':
return action.accountDid === undefined || action.accountDid === did
? 'clear'
: 'keep-latest'
return action.accountDid === did ? 'clear' : 'keep-latest'
case 'logged-out-every-account':
return 'clear'
case 'received-session-event':
@@ -175,8 +173,8 @@ function getTokenWriteMode(
return latestAccount.refreshJwt ? 'replace' : 'keep-latest'
}
if (action.sessionEvent === 'expired') {
return latestAccount.refreshJwt &&
latestAccount.refreshJwt !== action.expiredRefreshJwt
if (!action.expiredRefreshJwt) return 'clear'
return latestAccount.refreshJwt !== action.expiredRefreshJwt
? 'keep-latest'
: 'clear'
}