mirror of
https://github.com/mudabbir-ahmad/peworkshop.git
synced 2026-10-07 19:50:20 +00:00
fixed elapsed timer on clue page cannot fix it on admin page. I am done. now to move on to the styling to match UI
This commit is contained in:
1 parent
4cd449c0cf
commit
8fd2cabbe0
10 files changed
+226
-136
No files matched your search
@@ -1,20 +1,16 @@
|
||||
import jwt from "jsonwebtoken";
|
||||
|
||||
// Get JWT secret from environment or use fallback
|
||||
const JWT_SECRET =
|
||||
process.env.NEXTAUTH_SECRET ||
|
||||
process.env.JWT_SECRET ||
|
||||
"your-fallback-secret-should-be-at-least-32-chars";
|
||||
|
||||
// Create a new JWT token
|
||||
export function createToken(payload) {
|
||||
// Check if payload already has an expiration date set
|
||||
const options = payload.exp ? {} : { expiresIn: "30d" };
|
||||
|
||||
return jwt.sign(payload, JWT_SECRET, options);
|
||||
}
|
||||
|
||||
// Verify a JWT token
|
||||
export function verifyToken(token) {
|
||||
try {
|
||||
if (!token) {
|
||||
@@ -26,13 +22,11 @@ export function verifyToken(token) {
|
||||
|
||||
const decoded = jwt.verify(token, JWT_SECRET);
|
||||
|
||||
// Validate that we have the minimum required fields
|
||||
if (!decoded.sub && !decoded.id) {
|
||||
console.error("Token missing required user identifier");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Log successful token verification with user ID
|
||||
console.log(
|
||||
"Token verified successfully for user:",
|
||||
decoded.sub || decoded.id
|
||||
@@ -40,7 +34,6 @@ export function verifyToken(token) {
|
||||
|
||||
return decoded;
|
||||
} catch (error) {
|
||||
// Provide detailed error logs
|
||||
if (error.name === "TokenExpiredError") {
|
||||
console.error("Token expired at:", error.expiredAt);
|
||||
} else if (error.name === "JsonWebTokenError") {
|
||||
|
||||
Reference in new issue
Block a user