I'm using express-jwt for athentication, and the following is my code:
api>routes/index.js:
var express = require('express'); var router = express.Router(); var jwt = require('express-jwt'); var auth = jwt({ secret: 'thisIsSecret', requestProperty: 'auth' }); after this inside index.js when i use auth middleware in
router.post('/locations/:locationId/reviews', auth, ctrlReviews.reviewsCreate); route, when want to post reviews data with post-man, request goes to loading, and no response appear, but if remove auth from route request give response. I have also checked with
var auth = jwt({ secret: process.env.JWT_SECRET, userProperty: 'payload' });
unautorizedErrorand catched that inapp.jssomething likeapp.use(function (err, req, res, next) { if (err.name === 'UnauthorizedErorr') { res.status(401); res.json("message : " + err.name + " : " + err.message); } });and expect a message response.app.js(UnauthorizedErorr). Thank u