0
使用passportjs進行身份驗證。當用戶註冊時,我想要顯示一條消息,讓他們知道他們現在可以使用他們的帳戶登錄。截至目前,報名也記錄他們會拋出我的通知功能:Passportjs PREVENT註冊後自動登錄
- 「你現在可以報名參加」
- 「你已經登錄」
和
- 「歡迎新用戶」
我如何避免這種情況?我嘗試req.logout()
到底verifySignup()
達到並沒有骰子。
我的路由器:
router.route('/login')
.get(function(req, res){
// If the user is already logged in, redirect them to the dashboard
if(req.isAuthenticated()) {
req.flash('alert', 'You are already logged in');
res.redirect('/');
} else {
// Otherwise, allow them to login
// Redirect them to the login pages
res.render('login',
{ host: req.baseUrl,
error: req.flash('error'),
success: req.flash('success'),
alert: req.flash('alert')
});
}
}).post(passport.authenticate('local-login', {
successRedirect: '/',
failureRedirect: '/login',
badRequestMessage: "You need to enter your username and password",
failureFlash: true // allow flash
})
);
router.route('/signup')
.get(function(req, res){
// If the user is already logged in, redirect them to the dashboard
if(req.isAuthenticated()) {
req.flash('alert', 'You must first log out before signing up for a new account');
res.redirect('/');
} else {
// Otherwise, allow them to signup
// Redirect them to the signup pages
res.render('signup',
{ host: req.baseUrl,
error: req.flash('error'),
success: req.flash('success'),
alert: req.flash('alert')
});
}
}).post(passport.authenticate('local-signup', {
successRedirect: '/login',
failureRedirect: '/signup',
badRequestMessage: "You must fill in all of the form fields.",
failureFlash: true // allow flash
})
);