Initial commit of CK-QR Platform

This commit is contained in:
Mohan Ki
2026-07-27 13:42:18 +05:30
commit 60dcb029dc
19 changed files with 2582 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
const jwt = require('jsonwebtoken');
const verifyToken = (req, res, next) => {
let token = req.headers['authorization'];
// Check cookies if no auth header
if (!token && req.cookies && req.cookies.token) {
token = req.cookies.token;
} else if (token && token.startsWith('Bearer ')) {
token = token.slice(7, token.length).trimLeft();
}
if (!token) return res.status(403).json({ error: 'Token missing from header' });
jwt.verify(token, process.env.JWT_SECRET || 'supersecret123', (err, decoded) => {
if (err) return res.status(401).json({ error: 'Unauthorized' });
req.user = decoded;
next();
});
};
module.exports = { verifyToken };