sign in and register fixes for looped and forwarded pages
This commit is contained in:
parent
5257a0d2fe
commit
ffccff85d4
6 changed files with 68 additions and 20 deletions
15
lib/jwt.ts
Normal file
15
lib/jwt.ts
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// lib/jwt.ts
|
||||
export function jwtExp(token?: string | null): number | null {
|
||||
if (!token) return null;
|
||||
try {
|
||||
const payload = JSON.parse(Buffer.from(token.split(".")[1], "base64").toString("utf8"));
|
||||
return typeof payload?.exp === "number" ? payload.exp : null;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function isJwtValid(token?: string | null): boolean {
|
||||
const exp = jwtExp(token);
|
||||
return !!exp && exp * 1000 > Date.now();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue