setup features

This commit is contained in:
2026-01-29 00:24:10 -05:00
parent 787c97a52f
commit 4a6e2c307c
34 changed files with 2891 additions and 71 deletions

View File

@@ -0,0 +1,19 @@
import jwt from 'jsonwebtoken';
export const authMiddleware = (req, res, next) => {
const authHeader = req.headers.authorization;
if (!authHeader || !authHeader.startsWith('Bearer ')) {
return res.status(401).json({ error: 'No token provided' });
}
const token = authHeader.substring(7);
try {
const decoded = jwt.verify(token, process.env.JWT_SECRET);
req.user = decoded; // { userId, email, username }
next();
} catch (error) {
return res.status(401).json({ error: 'Invalid token' });
}
};