fetchhistory changes
Deploy Node App / deploy (push) Successful in 8s

This commit is contained in:
Gitea
2026-06-03 12:16:02 +05:30
parent be6e3f597d
commit 1892f6f94a
+13 -7
View File
@@ -1,19 +1,25 @@
const jwt = require('jsonwebtoken'); const jwt = require('jsonwebtoken');
const authMiddleware = (req, res, next) => { const authMiddleware = (req, res, next) => {
const JWT_SECRET = 'secretkey'; const JWT_SECRET = 'secretkey';
const authHeader = req.headers.authorization; const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) { if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Unauthorized: Missing or invalid token format' }); return res.status(401).json({
} success: false,
message: 'Unauthorized: Missing or invalid token format'
});
}
const token = authHeader.split(' ')[1]; const token = authHeader.split(' ')[1];
try { try {
const decoded = jwt.verify(token, JWT_SECRET); const decoded = jwt.verify(token, JWT_SECRET);
req.user = decoded; req.user = decoded;
next(); next();
} catch (error) { } catch (error) {
return res.status(401).json({
return res.status(401).json({ error: 'Unauthorized: Invalid token' }); success: false,
message: 'Unauthorized: Invalid token'
});
} }
}; };