This means, authorization is denied.
This means, authorization can't be completed due to something wrong in the client side.
| const jwt = requier("jsonwebtoken") | |
| function auth(req, res, next) { | |
| const token = req.header("x-auth-token") | |
| // Check for token | |
| if (!token) res.status(401).json({msg: "No token, authorization denied"}) | |
| try { | |
| // Verify token | |
| const deciphered = jwt.verify(token, process.env.JWT_SECRET); // returns payload | |
| // Add user from payload (to req object) | |
| req.user = deciphered; | |
| next(); | |
| } catch (error) { | |
| res.status(400).json({msg: "Bad Token, Token is not valid."}) | |
| } | |
| } | |
| module.exports = auth; |