Track rotated auth tokens

zio/stable
Paul Frazee 2022-11-21 16:17:40 -06:00
parent ed146a582c
commit b2dba9a15b
2 changed files with 16 additions and 1 deletions

View File

@ -34,6 +34,8 @@ export async function setupState() {
if (!api.sessionManager.session && rootStore.session.isAuthed) { if (!api.sessionManager.session && rootStore.session.isAuthed) {
// reset session // reset session
rootStore.session.clear() rootStore.session.clear()
} else if (api.sessionManager.session) {
rootStore.session.updateAuthTokens(api.sessionManager.session)
} }
}) })

View File

@ -1,6 +1,9 @@
import {makeAutoObservable} from 'mobx' import {makeAutoObservable} from 'mobx'
import {sessionClient as AtpApi} from '../../third-party/api/index' import {sessionClient as AtpApi} from '../../third-party/api/index'
import type {SessionServiceClient} from '../../third-party/api/src/index' import type {
SessionServiceClient,
Session,
} from '../../third-party/api/src/index'
import type * as GetAccountsConfig from '../../third-party/api/src/client/types/com/atproto/server/getAccountsConfig' import type * as GetAccountsConfig from '../../third-party/api/src/client/types/com/atproto/server/getAccountsConfig'
import {isObj, hasProp} from '../lib/type-guards' import {isObj, hasProp} from '../lib/type-guards'
import {RootStoreModel} from './root-store' import {RootStoreModel} from './root-store'
@ -88,6 +91,16 @@ export class SessionModel {
this.data = data this.data = data
} }
updateAuthTokens(session: Session) {
if (this.data) {
this.setState({
...this.data,
accessJwt: session.accessJwt,
refreshJwt: session.refreshJwt,
})
}
}
private configureApi(): boolean { private configureApi(): boolean {
if (!this.data) { if (!this.data) {
return false return false