feat: basic api setup and boilerplate

This commit is contained in:
ARJUN S THAMPI
2026-03-12 14:15:44 +05:30
commit 521a1fea79
24 changed files with 684 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
import {verifyToken} from "../utils/jwt.js";
export default function jwtAuthMiddleware(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.split(" ")[1];
try {
const user = verifyToken(token);
req.user = user;
next();
} catch (err) {
return res.status(401).json({error: "Invalid or expired token"});
}
}