私はPassportJSを使用しています。サインアップとログインの機能は非常にスムーズです。ユーザが一度認証された場合、passportjsに再度ログインすることを禁止しますか?
私はPassportJS(私もセッションを使用しています)に直面している唯一の問題は、ユーザーがログインしていてもサインアップ/ログインURLに戻ってサインアップしたりログインし直すことができることです!
これは私を魅了しています。誰かが修正/提案をしている場合は、それを置いてください。
UPDATE - の1
垣間見る私routes.js
:(あなたがアクセス制御の任意の並べ替えを作成していない
app.get('*', function(req, res, next) {
if (req.url.indexOf('/users/login') < 0 &&
req.url.indexOf('/users/signup') < 0) {
req.session.returnTo = null;
}
next();
});
// =====================================
// HOME PAGE (with login links) ========
// =====================================
app.get('/', sabSettings, function(req, res) {
Setting.findOne(function(err, setting) {
if (err)
throw err;
// console.log(setting);
res.render('index', { title: 'eduBird | Reach the glory', setting: req.setting }); // load the index file
});
});
// =====================================
// LOGIN ===============================
// =====================================
// show the login form
app.get('/login', sabSettings, function(req, res) {
// render the page and pass in any flash data if it exists
res.render('login', {
message: req.flash('loginMessage'),
errors: req.flash('error'),
title: 'Login | eduBird',
setting: req.setting
});
});
// process the login form
app.post('/login', passport.authenticate('local-login', {
successReturnToOrRedirect: '/loggedin',
failureRedirect: '/login',
failureFlash: true
}));
// =====================================
// SIGNUP ==============================
// =====================================
// show the signup form
app.get('/signup', sabSettings, function(req, res) {
// render the page and pass in any flash data if it exists
process.nextTick(function() {
res.render('signup', {
message: req.flash('signupMessage'),
errors: req.flash('error'),
title: 'Register | eduBird',
setting: req.setting
});
});
});
// process the signup form
app.post('/signup', passport.authenticate('local-signup', {
successReturnToOrRedirect: '/profile/welcome',
failureRedirect: '/signup',
failureFlash: true
}));
コードAnimeshを提供できますか? –
それがあなたの問題を解決するかどうか教えてください –
@Kudzaiそれは働いた。ありがとう。 –