jwtExpiry

tcmts.atproto.jwtExpiry · #2jpxlsqj · term · runs on the server

uses Buffer

When a token from com.atproto.server.createSession expires (ms since the epoch): its exp, or in 5 minutes if it doesn't say.

export function jwtExpiry(jwt: string): number {
  try {
    const exp = (
      JSON.parse(Buffer.from(jwt.split(".")[1]!, "base64url").toString("utf8")) as { exp?: unknown }
    ).exp;
    if (typeof exp === "number") return exp * 1000;
  } catch {}
  return Date.now() + 5 * 60 * 1000;
}

used by