更新:我已下载express-4.x-local-example,但似乎无法正常运行。我有什么遗失的东西吗?
我试图为护照制定本地策略,但它没有被解雇。输入凭据后,页面将重定向到failureRedirect。
app.js
const express = require('express')
, app = express()
, mainRouter = require('./controllers/mainRouter');
mainRouter(app);
mainRouter.js
const bodyParser = require('body-parser')
, passport = require('passport')
, passportConfig = require('../config/passport');
passportConfig(passport);
module.exports = (app) => {
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(passport.initialize());
app.use(passport.session());
app.post('/login', passport.authenticate(('local'), {
successRedirect: '/',
failureRedirect: 'login/',
})
);
}
passport.js
const LocalStrategy = require('passport-local').Strategy;
module.exports = (passport) => {
passport.use(new LocalStrategy({usernameField: 'email'},
(email, password, done) => {
console.log('This message is not being logged.');
})
);
}
答案 0 :(得分:0)
您实际上并未在mainRouter.js文件中调用策略。
在app.post之前,添加passport.use(passportConfig);