我有一个使用passport-local
策略授权的简单应用。用户向/login
提交表单,将其重定向到路由器,然后进行授权:
app.js (一部分)
const { indexRouter } = require('./routes/index');
app.use('/login', indexRouter);
passport.use(
'local',
new LocalStrategy(
{
passReqToCallback: true,
usernameField: 'email',
passwordField: 'name'
},
(req, email, name, done) => {
console.log('Logging in: ', email, name);
if (email) {
email = email.trim();
name = name.trim();
return authorizeUser(email, name, done);
}
return done(new Error('User not authorized: no email provided'), null, false);
}
)
);
routes / index.js
router.post('/', passport.authenticate('local'), (req, res) => {
res.render('user/success');
});
但是,我想要一个绕过链接(例如,/bypass
),该链接将授权测试用户并重定向到成功页面而无需任何凭据。我该怎么做?