im trying to do the authentication using passport-local and i don't get any response for the /login route, basicly i followed the passport tutorial to set the local strategy like this:
var express = require('express');
var User = require('../models/User');
var router = express.Router();
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
router.post('/', function (req, res, next) {
var username = req.body.username;
var password = req.body.password;
passport.use(new LocalStrategy(
function (username, password, done) {
User.findOne({ username: username }, function (err, user) {
if (err) { return done(err); }
if (!user) {
return res.status(406).json({message: 'There is no user with those fields'});
}
if (!user.validPassword(password)) {
return res.status(406).json({message: 'Invalid password'});
}
return res.status(200).json({message: 'logged in'});
});
}
));
});
module.exports = router;
i want to associate the passport local with my post route so i set everything inside the specific route to test the behaviour, am i doing something wrong here?
via Antonio Costa
No comments:
Post a Comment