MCPcopy Create free account
hub / github.com/basir/node-react-ecommerce / isAuth

Function isAuth

backend/util.js:18–34  ·  view source on GitHub ↗
(req, res, next)

Source from the content-addressed store, hash-verified

16};
17
18const isAuth = (req, res, next) => {
19 const token = req.headers.authorization;
20
21 if (token) {
22 const onlyToken = token.slice(7, token.length);
23 jwt.verify(onlyToken, config.JWT_SECRET, (err, decode) => {
24 if (err) {
25 return res.status(401).send({ message: 'Invalid Token' });
26 }
27 req.user = decode;
28 next();
29 return;
30 });
31 } else {
32 return res.status(401).send({ message: 'Token is not supplied.' });
33 }
34};
35
36const isAdmin = (req, res, next) => {
37 console.log(req.user);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected