0
我使用express和passport來構建休息api後端,並且似乎我的localStrategy沒有按請求調用。nodejs,passportjs本地策略未運行
var express = require('express');
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var app = express();
var port = process.env.PORT || 3000;
app.get('/', function(req, res) {
res.render('index.ejs');
});
app.get('/login', function(req, res) {
console.log('login /GET');
res.render('login.ejs');
});
passport.use('local', new LocalStrategy({
usernameField : 'username',
passwordField : 'password'
},
function(username, password, done) {
console.log('local strategy');
return done(null, {username : 'username'});
}
));
app.post('/login', function(req, res, next){
passport.authenticate('local', function(err, user, info) {
console.log('auth run');
if (err) {
return next(err);
}
if (!user) {
return res.redirect('/login');
}
req.logIn(user, function(err) {
if (err) { return next(err); }
return res.redirect('/users/' + user.username);
});
})(req, res, next);
});
app.listen(port);
console.log('listenting http://localhost:' + port);
我的登錄請求會在控制檯中顯示消息而觸發,但這就是它?
任何想法?