This commit is contained in:
2026-05-07 23:18:34 +02:00
commit 07c58f23ab
39 changed files with 6044 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
import jwt from 'jsonwebtoken'
export const validateToken = async (req, res, next) => {
const authHeader = req.headers.authorization
if (!authHeader)
return res.status(401).json({ error: "Invalid token" })
const token = authHeader.split(' ')[1]
try {
req.user = jwt.verify(token, process.env.JWT_SECRET)
} catch (error) {
return res.status(401).json({ error: "Invalid token" })
}
next()
}