How to use passport authentication?

26 views Asked by At

I knew on GraphQL. Now I want to add user authentication using passport-local-mongoose with passport.js.

But response don't have graphql. How to solve this. Here is my solution, but this doesn't work get error: TypeError: res.end is not a function :

login: async ({ email, password }, req, res) => {
    const user = new User({
      email,
      password
    })
    req.login(user, function (err) {
      if (err) {
        console.log(err)
      } else {
        passport.authenticate('local')(req, function (err) {
          throw err
        })
      }
    })
    console.log(req.user)
    return req.user
  }

How to solve this problem or how to authentication using passport.js ?

0

There are 0 answers