mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed issue with login page.
This commit is contained in:
1 parent
11fc5c8b3d
commit
84f010cb87
6 files changed
+153
-30
No files matched your search
@@ -93,7 +93,29 @@ export function createToken(payload) {
|
||||
|
||||
export function verifyToken(token) {
|
||||
try {
|
||||
return jwt.verify(token, JWT_SECRET);
|
||||
if (!token) return null;
|
||||
const parts = token.split(".");
|
||||
if (parts.length === 2) {
|
||||
// Custom token verification
|
||||
const [encodedData, signature] = parts;
|
||||
const expectedSignature = Buffer.from(
|
||||
`${encodedData}.${JWT_SECRET}`
|
||||
).toString("base64");
|
||||
if (signature !== expectedSignature) {
|
||||
console.error("Signature mismatch");
|
||||
return null;
|
||||
}
|
||||
const data = JSON.parse(
|
||||
Buffer.from(encodedData, "base64").toString("utf-8")
|
||||
);
|
||||
if (data.exp && data.exp < Math.floor(Date.now() / 1000)) return null;
|
||||
return data;
|
||||
} else if (parts.length === 3) {
|
||||
// Standard JWT verification
|
||||
return jwt.verify(token, JWT_SECRET);
|
||||
} else {
|
||||
throw new Error("Invalid token format");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Token verification error:", error);
|
||||
return null;
|
||||
|
||||
Reference in new issue
Block a user