MCPcopy Create free account
hub / github.com/Zoo-Code-Org/Zoo-Code / decodeToken

Function decodeToken

apps/cli/src/lib/auth/token.ts:15–35  ·  view source on GitHub ↗
(token: string)

Source from the content-addressed store, hash-verified

13}
14
15function 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
37export function isTokenExpired(token: string, bufferSeconds = 24 * 60 * 60): boolean {
38 const decoded = decodeToken(token)

Callers 2

isTokenExpiredFunction · 0.85
getTokenExpirationDateFunction · 0.85

Calls 3

fromMethod · 0.80
parseMethod · 0.80
toStringMethod · 0.65

Tested by

no test coverage detected