使用 Passport 和 Express,我成功地处理了用户 session 。因为我有一些页面,不需要登录就可以查看,一个用户可以登录多个页面。
我应该如何处理 passport.authenticate 以在当前页面上重定向,并增加用户数据。
app.post('/login',
passport.authenticate('local', { successRedirect: '/',
failureRedirect: '/login',
failureFlash: true })
);
可能是带有 res.send(req.user)
的自定义回调。由于我完全不熟悉,我只是对此提出建议。
最佳答案
用户信息将放在req.user
"by passport"
app.post('/login',
passport.authenticate('local-login', {
successRedirect : 'back', // redirect back to the previous page
failureRedirect : 'back', // redirect back to the previous page
failureFlash : true
})
);
关键字back
重定向到上一页。
关于node.js - Node 和 Passport : stay on the same page after login,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25424740/