🚀 Patch auto

This commit is contained in:
karim hassan
2025-08-24 23:00:40 +00:00
parent 92e6afff00
commit f1103d67a0
1314 changed files with 2511 additions and 562 deletions

14
src/middleware/auth.js Normal file
View File

@@ -0,0 +1,14 @@
import jwt from 'jsonwebtoken';
export function requireAuth(req, res, next){
const hdr = req.headers.authorization || '';
const token = hdr.startsWith('Bearer ') ? hdr.slice(7) : null;
if(!token) return res.status(401).json({error:'Missing token'});
try{
const payload = jwt.verify(token, process.env.JWT_SECRET || 'devsecret');
req.user = payload;
next();
}catch(e){
res.status(401).json({error:'Invalid token'});
}
}