register + login + mdp hash

This commit is contained in:
gprunet
2026-01-10 16:27:15 +01:00
parent f00152523f
commit a1c08ab9dc
7 changed files with 192 additions and 70 deletions
+21
View File
@@ -0,0 +1,21 @@
const jwt = require('jsonwebtoken');
module.exports = function authMiddleware(req, res, next)
{
const header = req.headers.authorization;
if (!header)
return (res.status(401).json({error: 'Missing token'}));
const token = header.split(' ')[1];
try
{
const payload = jwt.verify(token, process.env.JWT_SECRET);
req.user = payload;
next();
}
catch
{
res.status(401).json({error: 'Invalid token'});
}
};