forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {jwtDecode} from 'jwt-decode'
2
3import {logger} from '#/logger'
4
5/**
6 * Simple check if a JWT token has expired. Does *not* validate the token or check for revocation status,
7 * just checks the expiration time.
8 *
9 * @param token The JWT token to check.
10 * @returns `true` if the token has expired, `false` otherwise.
11 */
12export function isJwtExpired(token: string) {
13 try {
14 const payload = jwtDecode(token)
15
16 if (!payload.exp) return true
17 const now = Math.floor(Date.now() / 1000)
18 return now >= payload.exp
19 } catch {
20 logger.error(`session: could not decode jwt`)
21 return true // invalid token or parse error
22 }
23}