You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How to exclude a route from jwt token verification
router.use((req, res, next) => {
const r = req;
// check header or url parameters or post parameters for token
// const token = req.body.token || req.query.token || req.headers['x-access-token'];
const token = req.body.token || req.query.token || req.headers.authorization;
// decode token
if (token) {
// verifies secret and checks exp
jwt.verify(token, req.app.get('superSecret'), (err, decoded) => {
if (err) {
// res.json({ success: false, message: 'Failed to authenticate token.' });
return res.status(401).send({
success: false,
message: 'Failed to authenticate token.'
});
} else {
// if everything is good, save to request for use in other routes
r.decoded = decoded;
next();
// console.log(decoded);
}
// return {};
});
} else {
// if there is no token
// return an error
return res.status(403).send({
success: false,
message: 'No token provided.'
});
}
});
In this I want to exclude some router from token verification (ex: user registration route). How can I do that.
I have tried putting that route above jwt.verfication code but still it is not working
The text was updated successfully, but these errors were encountered:
Declare the routes you want to exclude before the function const excluded = ['/login', '/users'];
then do this before requesting your token if (excluded.indexOf(req.url) > -1) return next();
How to exclude a route from jwt token verification
In this I want to exclude some router from token verification (ex: user registration route). How can I do that.
I have tried putting that route above jwt.verfication code but still it is not working
The text was updated successfully, but these errors were encountered: