forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {jwtDecode} from 'jwt-decode'
2
3import {isJwtExpired} from '#/lib/jwt'
4import {hasProp} from '#/lib/type-guards'
5import * as persisted from '#/state/persisted'
6import {type SessionAccount} from './types'
7
8export function readLastActiveAccount() {
9 const {currentAccount, accounts} = persisted.get('session')
10 return accounts.find(a => a.did === currentAccount?.did)
11}
12
13export function isSignupQueued(accessJwt: string | undefined) {
14 if (accessJwt) {
15 const sessData = jwtDecode(accessJwt)
16 return (
17 hasProp(sessData, 'scope') &&
18 sessData.scope === 'com.atproto.signupQueued'
19 )
20 }
21 return false
22}
23
24export function isSessionExpired(account: SessionAccount) {
25 if (account.accessJwt) {
26 return isJwtExpired(account.accessJwt)
27 } else {
28 return true
29 }
30}