Closed caiguanhao closed 11 years ago
Example code:
// login for normal users: passport.use(new LocalStrategy({ strategyName: 'local' }, ... ); app.post('/login', passport.authenticate('local', { successReturnToOrRedirect: '/', failureRedirect: '/login' })); app.get('/', function(req, res, next){ if (req.user) { res.render('index'); } else { res.redirect('/login'); } }); // login for admins: passport.use(new LocalStrategy({ strategyName: 'local-admin' }, ... ); app.post('/admin/login', passport.authenticate('local-admin', { successReturnToOrRedirect: '/admin', failureRedirect: '/admin/login' })); app.get('/admin', function(req, res, next){ if (req.user && req.user.is_admin) { res.render('admin/index'); } else { res.redirect('/admin/login'); } });
You can set the strategy name when registering with Passport:
passport.use(new LocalStrategy( ... )); passport.use('local-admin', new LocalStrategy( ... ));
Example code: