INNER CODE UNIT · JavaScript
isAuth
basir/mern-amazona · backend/utils.js:26
export const isAuth = (req, res, next) => {
const authorization = req.headers.authorization;
if (authorization) {
const token = authorization.slice(7, authorization.length); // Bearer XXXXXX
jwt.verify(token, process.env.JWT_SECRET, (err, decode) => {
if (err) {
res.status(401).send({ message: 'Invalid Token' });
} else {
req.user = decode;
next();
}
});
} else {
res.status(401).send({ message: 'No Token' });
}
};
export const isAdmin = (req, res, next) => {