···872872 expect(state.accounts[0].accessJwt).toBe('alice-access-jwt-3')
873873 })
874874875875- it('ignores updates from a stale agent', () => {
875875+ it('accepts updates from a stale agent', () => {
876876 let state = getInitialState([])
877877878878 const agent1 = new BskyAgent({service: 'https://alice.com'})
···928928 ])
929929 expect(state.accounts.length).toBe(2)
930930 expect(state.accounts[1].did).toBe('alice-did')
931931- // Should retain the old values because Alice is not active.
932932- expect(state.accounts[1].handle).toBe('alice.test')
933933- expect(state.accounts[1].accessJwt).toBe('alice-access-jwt-1')
934934- expect(state.accounts[1].refreshJwt).toBe('alice-refresh-jwt-1')
931931+ // Should update Alice's tokens because otherwise they'll be stale.
932932+ expect(state.accounts[1].handle).toBe('alice-updated.test')
933933+ expect(state.accounts[1].accessJwt).toBe('alice-access-jwt-2')
934934+ expect(state.accounts[1].refreshJwt).toBe('alice-refresh-jwt-2')
935935 expect(printState(state)).toMatchInlineSnapshot(`
936936 {
937937 "accounts": [
···948948 "service": "https://bob.com/",
949949 },
950950 {
951951- "accessJwt": "alice-access-jwt-1",
951951+ "accessJwt": "alice-access-jwt-2",
952952 "deactivated": false,
953953 "did": "alice-did",
954954- "email": undefined,
954954+ "email": "alice@foo.bar",
955955 "emailAuthFactor": false,
956956 "emailConfirmed": false,
957957- "handle": "alice.test",
957957+ "handle": "alice-updated.test",
958958 "pdsUrl": undefined,
959959- "refreshJwt": "alice-refresh-jwt-1",
959959+ "refreshJwt": "alice-refresh-jwt-2",
960960 "service": "https://alice.com/",
961961 },
962962 ],
···988988 ])
989989 expect(state.accounts.length).toBe(2)
990990 expect(state.accounts[0].did).toBe('bob-did')
991991- // Should update the values because Bob is active.
991991+ // Should update Bob's tokens because otherwise they'll be stale.
992992 expect(state.accounts[0].handle).toBe('bob-updated.test')
993993 expect(state.accounts[0].accessJwt).toBe('bob-access-jwt-2')
994994 expect(state.accounts[0].refreshJwt).toBe('bob-refresh-jwt-2')
···10081008 "service": "https://bob.com/",
10091009 },
10101010 {
10111011- "accessJwt": "alice-access-jwt-1",
10111011+ "accessJwt": "alice-access-jwt-2",
10121012 "deactivated": false,
10131013 "did": "alice-did",
10141014- "email": undefined,
10141014+ "email": "alice@foo.bar",
10151015 "emailAuthFactor": false,
10161016 "emailConfirmed": false,
10171017- "handle": "alice.test",
10171017+ "handle": "alice-updated.test",
10181018 "pdsUrl": undefined,
10191019- "refreshJwt": "alice-refresh-jwt-1",
10191019+ "refreshJwt": "alice-refresh-jwt-2",
10201020 "service": "https://alice.com/",
10211021 },
10221022 ],
···10301030 }
10311031 `)
1032103210331033- // Ignore other events for inactive agent too.
10331033+ // Ignore other events for inactive agent.
10341034 const lastState = state
10351035 agent1.session = undefined
10361036 state = run(state, [
+7-2
src/state/session/reducer.ts
···6868 switch (action.type) {
6969 case 'received-agent-event': {
7070 const {agent, accountDid, refreshedAccount, sessionEvent} = action
7171- if (agent !== state.currentAgentState.agent) {
7272- // Only consider events from the active agent.
7171+ if (
7272+ refreshedAccount === undefined &&
7373+ agent !== state.currentAgentState.agent
7474+ ) {
7575+ // If the session got cleared out (e.g. due to expiry or network error) but
7676+ // this account isn't the active one, don't clear it out at this time.
7777+ // This way, if the problem is transient, it'll work on next resume.
7378 return state
7479 }
7580 if (sessionEvent === 'network-error') {