Fix: test the session during resume to ensure it's valid
This commit is contained in:
@@ -286,17 +286,33 @@ export class SessionModel {
|
||||
* Attempt to resume a session that we still have access tokens for.
|
||||
*/
|
||||
async resumeSession(account: AccountData): Promise<boolean> {
|
||||
if (account.accessJwt && account.refreshJwt) {
|
||||
this.setState({
|
||||
service: account.service,
|
||||
accessJwt: account.accessJwt,
|
||||
refreshJwt: account.refreshJwt,
|
||||
handle: account.handle,
|
||||
did: account.did,
|
||||
})
|
||||
} else {
|
||||
if (!(account.accessJwt && account.refreshJwt && account.service)) {
|
||||
return false
|
||||
}
|
||||
|
||||
// test that the session is good
|
||||
const api = AtpApi.service(account.service)
|
||||
api.sessionManager.set({
|
||||
refreshJwt: account.refreshJwt,
|
||||
accessJwt: account.accessJwt,
|
||||
})
|
||||
try {
|
||||
const sess = await this.rootStore.api.com.atproto.session.get()
|
||||
if (!sess.success || sess.data.did !== account.did) {
|
||||
return false
|
||||
}
|
||||
} catch (_e) {
|
||||
return false
|
||||
}
|
||||
|
||||
// session is good, connect
|
||||
this.setState({
|
||||
service: account.service,
|
||||
accessJwt: account.accessJwt,
|
||||
refreshJwt: account.refreshJwt,
|
||||
handle: account.handle,
|
||||
did: account.did,
|
||||
})
|
||||
return this.connect()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user