Added PFM Console UI project
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Lightweight browser-safe JWT payload decoder without external native dependencies.
|
||||
*/
|
||||
export function parseJwtClaims(token: string): Record<string, any> {
|
||||
if (!token || typeof token !== 'string') return {};
|
||||
try {
|
||||
const parts = token.split('.');
|
||||
if (parts.length < 2) return {};
|
||||
const base64Url = parts[1];
|
||||
const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
||||
const jsonPayload = decodeURIComponent(
|
||||
window
|
||||
.atob(base64)
|
||||
.split('')
|
||||
.map((c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2))
|
||||
.join('')
|
||||
);
|
||||
return JSON.parse(jsonPayload);
|
||||
} catch (err) {
|
||||
console.debug('Failed to decode JWT claims payload:', err);
|
||||
return {};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user