[Session] Remove imperative agent restoration call

Co-authored-by: dan <dan.abramov@gmail.com>
This commit is contained in:
Eric Bailey
2024-05-03 04:16:51 +01:00
committed by Dan Abramov
parent cdf7a1957a
commit 6e9320163a
+16 -29
View File
@@ -332,35 +332,22 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
if (isSessionExpired(account)) {
logger.debug(`session: attempting to resume using previous session`)
try {
const freshAccount = await resumeSessionWithFreshAccount()
__globalAgent = agent
await fetchingGates
setState(s => {
return {
accounts: [
freshAccount,
...s.accounts.filter(a => a.did !== freshAccount.did),
],
currentAgentState: {
did: freshAccount.did,
agent: agent,
},
needsPersist: true,
}
})
} catch (e) {
/*
* Note: `agent.persistSession` is also called when this fails, and
* we handle that failure via `createPersistSessionHandler`
*/
logger.info(`session: resumeSessionWithFreshAccount failed`, {
message: e,
})
__globalAgent = PUBLIC_BSKY_AGENT
// TODO: This needs a setState.
}
const freshAccount = await resumeSessionWithFreshAccount()
__globalAgent = agent
await fetchingGates
setState(s => {
return {
accounts: [
freshAccount,
...s.accounts.filter(a => a.did !== freshAccount.did),
],
currentAgentState: {
did: freshAccount.did,
agent: agent,
},
needsPersist: true,
}
})
} else {
logger.debug(`session: attempting to reuse previous session`)