Add Oudelaa dashboard API integration
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled
هذا الالتزام موجود في:
23
oudelaa_dashboard/lib/auth/jwt.ts
Normal file
23
oudelaa_dashboard/lib/auth/jwt.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
export function parseJwtPayload(token: string): Record<string, unknown> | null {
|
||||
const parts = token.split(".");
|
||||
if (parts.length < 2) return null;
|
||||
|
||||
try {
|
||||
const normalized = parts[1].replace(/-/g, "+").replace(/_/g, "/");
|
||||
const decoded =
|
||||
typeof window !== "undefined"
|
||||
? window.atob(normalized)
|
||||
: Buffer.from(normalized, "base64").toString("utf8");
|
||||
return JSON.parse(decoded) as Record<string, unknown>;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function isJwtExpired(token: string, skewSeconds = 15): boolean {
|
||||
const payload = parseJwtPayload(token);
|
||||
const exp = typeof payload?.exp === "number" ? payload.exp : null;
|
||||
if (!exp) return false;
|
||||
const now = Math.floor(Date.now() / 1000);
|
||||
return exp <= now + skewSeconds;
|
||||
}
|
||||
المرجع في مشكلة جديدة
حظر مستخدم