Added gitignore
Deploy Node App / deploy (push) Failing after 3s

This commit is contained in:
Gitea
2026-05-25 15:23:04 +05:30
commit 192e8fc79c
10 changed files with 1766 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
const jwt = require('jsonwebtoken');
const authMiddleware = (req, res, next) => {
const JWT_SECRET = 'secretkey';
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Unauthorized: Missing or invalid token format' });
}
const token = authHeader.split(' ')[1];
try {
const decoded = jwt.verify(token, JWT_SECRET);
req.user = decoded;
next();
} catch (error) {
return res.status(401).json({ error: 'Unauthorized: Invalid token' });
}
};
module.exports = authMiddleware;