我无法弄清楚为什么passport
在成功认证到我的/dashboard
页面后会点头重定向我。我可以在浏览器的“网络”选项卡中看到该请求,但是我的页面没有更改,并停留在当前登录页面上。
app.use(passport.initialize());
app.use(passport.session());
passport.use(new LocalStrategy(
function(username, password, done) {
database.query('SELECT * FROM users WHERE email = ?', username, (error, result, fields) => {
if(error){
return done(error);
}
if(result[0] == undefined){
return done(null, false);
}
bcrypt.compare(password, result[0].password, function(err, res) {
if(!res){return done(null, false);}
});
return done(null, result[0]);
});
}
));
passport.serializeUser(function(user, done) {
done(null, user.email);
});
// used to deserialize the user
passport.deserializeUser(function(email, done) {
database.query("SELECT * FROM users WHERE email = ? ", email, function(err, result, fields){
done(err, result[0]);
});
});
router.post('/login',
passport.authenticate('local', { successRedirect: '/dashboard',
failureRedirect: '/' }));
router.get('/login', function(request, response){
response.render(path.resolve(__dirname, 'views', 'login.pug'));
})
router.get('/', function(request, response){
response.render(path.resolve(__dirname, 'views', 'register.pug'));
})
能帮我找出问题所在吗?
答案 0 :(得分:0)
问题是我阻止了我用来提交表单的按钮的默认行为,因此页面从未刷新,导致网页从未更新。