提问者:小点点

done不是passport.js中间件中的函数错误


我试图在passport.js中创建auth,当我在postman中测试我的错误时,我得到了以下错误。

done不是Strategy.passport.use.localStrategy[as_verify]中的函数(fullstack/twitter-clone/twitter-clone/twitter-api/middleware/auth.js:20:7)

这是我的auth.js中间件注册函数

passport.use('signup', new localStrategy({
    emailField : 'email',
    usernameField : 'username',
    passwordField : 'password'
}, async (email, username, password, done) => {
    try {
      //Save the information provided by the user to the the database
      const user = await User.create({ email, username, password });
      console.log(user);
      //Send the user information to the next middleware
      return done(null, user);
    } catch (error) {
      done(error);
    }
}));

这是我的注册控制器函数

exports.signup = passport.authenticate('signup', { session : false }) , async (req, res, next) => {
    res.json({
        message : 'Signup successful',
        user : req.user
    });
};

这就是我的路线

router.post('/signup', userController.signup);

有什么想法吗?


共1个答案

匿名用户

第一个参数是“req”,您错过了它。

passport.use('signup', new localStrategy({
    emailField : 'email',
    usernameField : 'username',
    passwordField : 'password'
}, async (req, email, username, password, done) => {
    try {
      //Save the information provided by the user to the the database
      const user = await User.create({ email, username, password });
      console.log(user);
      //Send the user information to the next middleware
      return done(null, user);
    } catch (error) {
      done(error);
    }
}));