mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
17 lines
576 B
JavaScript
17 lines
576 B
JavaScript
//#region src/jwt/parse-jwt.ts
|
|
/** Decode the payload of a JWT without verifying its signature, `undefined` for malformed tokens. */
|
|
function parseJwt(token) {
|
|
const base64Url = (token ?? "").split(".")[1];
|
|
if (!base64Url) return void 0;
|
|
try {
|
|
const base64 = base64Url.replace(/-/g, "+").replace(/_/g, "/");
|
|
const json = decodeURIComponent(atob(base64).split("").map((char) => `%${`00${char.charCodeAt(0).toString(16)}`.slice(-2)}`).join(""));
|
|
return JSON.parse(json);
|
|
} catch {
|
|
return;
|
|
}
|
|
}
|
|
//#endregion
|
|
export { parseJwt };
|
|
|
|
//# sourceMappingURL=parse-jwt.js.map
|