Devendra174's picture
Upload folder using huggingface_hub
f5071ca verified
raw
history blame contribute delete
650 Bytes
const jwt = require("jsonwebtoken");
require("dotenv").config();
const { SECRET_KEY_FOR_BCRYPT } = process.env;
module.exports = async (req, res, next) => {
try {
const jwtTokenFromClient = req.header("token");
if (!jwtTokenFromClient) {
return res.status(403).json("Not Authozied");
}
//jwt.verify compair 'token from client' and secretKeyFrom and if 'jwtTokenFromClient' and 'SECRET_KEY_FOR_BCRYPT' matched the its return payload
const payload = jwt.verify(jwtTokenFromClient, SECRET_KEY_FOR_BCRYPT);
req.user = payload;
next();
} catch (e) {
console.error(e.message);
return res.status(403).json("Not Authozied");
}
};