You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
427 B
19 lines
427 B
const jwt = require("jsonwebtoken");
|
|
require("dotenv").config();
|
|
|
|
module.exports = async (req, res, next) => {
|
|
try {
|
|
const jwtToken = req.header("token");
|
|
|
|
if (!jwtToken) {
|
|
return res.status(403).json("Not Authorized");
|
|
}
|
|
|
|
const payload = jwt.verify(jwtToken, process.env.jwtSecret);
|
|
req.user = payload.user;
|
|
next();
|
|
} catch (error) {
|
|
return res.status(403).json("Not Authorized");
|
|
}
|
|
};
|