Files
bsky-social-app/src/lib/jwt.ts
T
Eric Bailey f105b22054 [APP-1674] Add bday fallback for app passwords (#9513)
* Add bday fallback for app passwords

* Update birthdate copy, add isAppPassword handling on NoAccessScreen

* Update copy

* Update usage

* Bump API package

* HmmMMMmmm

Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>

* s/a/your

Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>

* Say hello

---------

Co-authored-by: surfdude29 <149612116+surfdude29@users.noreply.github.com>
(cherry picked from commit b47f5f023e)
2025-12-09 16:43:11 -06:00

30 lines
796 B
TypeScript

import {jwtDecode} from 'jwt-decode'
import {logger} from '#/logger'
/**
* Simple check if a JWT token has expired. Does *not* validate the token or check for revocation status,
* just checks the expiration time.
*
* @param token The JWT token to check.
* @returns `true` if the token has expired, `false` otherwise.
*/
export function isJwtExpired(token: string) {
try {
const payload = jwtDecode(token)
if (!payload.exp) return true
const now = Math.floor(Date.now() / 1000)
return now >= payload.exp
} catch {
logger.error(`session: could not decode jwt`)
return true // invalid token or parse error
}
}
export function isAppPassword(token: string) {
const payload = jwtDecode(token)
// @ts-ignore
return payload.scope === 'com.atproto.appPass'
}