Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

380 B
Raw Blame
import { isJsonObject } from "./is-json-object";

export function decodeJwtSegment(token: string, index: 0 | 1) {
  const segment = token.split(".")[index];
  if (!segment) return null;
  try {
    const value: unknown = JSON.parse(
      Buffer.from(segment, "base64url").toString("utf8"),
    );
    return isJsonObject(value) ? value : null;
  } catch {
    return null;
  }
}