express - Passport-jwt token get error messages from server -


i cannot figure out how pass error messages server client. searched docs, cannot should implement callback function return error message.

my server-side code looks this:

passport.js

var locallogin = new localstrategy(localoptions, function(email, password, done){  user.findone({   email: email  }, function(err, user, info){  if(err){   return done(err); }  if(!user){   return done(null, false, {message: 'user not found'}); }  user.comparepassword(password, function(err, ismatch){    if(err){     return done(err);   }    if(!ismatch){     return done(null, false, {message: 'passwords not match'});   }    return done(null, user);  });  });  }); 

router.js

> var requireauth = passport.authenticate('jwt', {session: false}), >     requirelogin = passport.authenticate('local', {session: false}); >  > module.exports = function(app){ >  >   var apiroutes = express.router(), >       authroutes = express.router(), >       todoroutes = express.router(); >  >   // auth routes   apiroutes.use('/auth', authroutes); >  >   authroutes.post('/register', authenticationcontroller.register);   > authroutes.post('/login', requirelogin, authenticationcontroller.login); 

in client receive error message.

response {_body: "unauthorized", status: 401, ok: false, statustext: "unauthorized", headers: headers…}headers: headersok: falsestatus: 401statustext: "unauthorized"type: 2url: "http://localhost:8083/api/auth/login"_body: "unauthorized"__proto__: body 


Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -