decodeJwtPayload (utils/jwt.ts)

AionUi · mobile/src/utils/jwt.ts · typescript · Apache-2.0
auth

Decodes JWT payload without external libs, returning the parsed object or null on failure.

// Source: https://github.com/iOfficeAI/AionUi | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Decode JWT payload without importing a library.
 * Returns the parsed payload object, or null on failure.
 */
export function decodeJwtPayload(token: string): { exp?: number } | null {
  try {
    const parts = token.split('.');
    if (parts.length !== 3) return null;
    // Base64url → base64
    const base64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
    const json = atob(base64);
    return JSON.parse(json);
  } catch {
    return null;
  }
}

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key