在Passport.js中对没有凭据的用户进行身份验证

时间:2018-10-30 07:14:00

标签: javascript node.js express passport.js

我有一个使用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),该链接将授权测试用户并重定向到成功页面而无需任何凭据。我该怎么做?

0 个答案:

没有答案