(token: string)
| 13 | } |
| 14 | |
| 15 | function decodeToken(token: string): DecodedToken | null { |
| 16 | try { |
| 17 | const parts = token.split(".") |
| 18 | |
| 19 | if (parts.length !== 3) { |
| 20 | return null |
| 21 | } |
| 22 | |
| 23 | const payload = parts[1] |
| 24 | |
| 25 | if (!payload) { |
| 26 | return null |
| 27 | } |
| 28 | |
| 29 | const padded = payload + "=".repeat((4 - (payload.length % 4)) % 4) |
| 30 | const decoded = Buffer.from(padded, "base64url").toString("utf-8") |
| 31 | return JSON.parse(decoded) as DecodedToken |
| 32 | } catch { |
| 33 | return null |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | export function isTokenExpired(token: string, bufferSeconds = 24 * 60 * 60): boolean { |
| 38 | const decoded = decodeToken(token) |
no test coverage detected