Post routes

This commit is contained in:
Andrew Trieu
2023-07-11 19:45:01 +03:00
committed by Andrew Trieu
parent 6c35f7d006
commit a25ea2d90a
9 changed files with 150 additions and 14 deletions

View File

@@ -0,0 +1,15 @@
import jwt from "jsonwebtoken";
export const verifyToken = (req, res, next) => {
try {
let token = req.header("Authorization");
if (!token) return res.status(403).json({ error: "Unauthorized" });
token = token.split(" ")[1];
const verifiedToken = jwt.verify(token, process.env.JWT_SECRET);
req.user = verifiedToken;
next();
} catch (error) {
res.status(500).json({ error: error.message });
}
};