node.js - login using passport always get error 400 bad request -
hi i'm using express implements passport, don't knows when i'm hit login url error 400 bad request. code :
main.js :
var express = require('express'); var app = express(); require('./config/passport'); require('./config/static')(app, express); require('./config/routes')(app); require('./config/seed')(); app.listen(3000, function () { console.log('example app listening on port 3000!'); });
passport.js :
var passport = require('passport'); var user = require('../api/model/user.model'); var localstrategy = require('passport-local').strategy; passport.use(new localstrategy({ usernamefield: 'email', passwordfield: 'password' }, function(username, password, done) { user.findone({ username: username }, function (err, user) { if (err) { return done(err); } if (!user) { return done(null, false); } if (!user.verifypassword(password)) { return done(null, false); } return done(null, user); }); } )); passport.serializeuser(function(user, done) { done(null, user.id); }); passport.deserializeuser(function(id, done) { user.findbyid(id, function (err, user) { done(err, user); }); });
routes.js :
var passport = require('passport'); module.exports = function (app) { app.post('/api/sign_in', passport.authenticate('local'), function (req, res) { res.json(res.body); }); app.get('/', function (req, res) { res.sendfile(path.resolve(__dirname + '/../public/index.html')); }); };
and when i'm hit url "/api/sign_in" 'post' method parameter '{email: "john@local.com", password: "12345"}', i'm error bad request 400
Comments
Post a Comment