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
})
);