passport / discuss

A forum for discussing topics related to the usage of Passport.js.
1 stars 0 forks source link

TypeError: OAuthStrategy requires a verify callback #70

Open jman13378 opened 2 years ago

jman13378 commented 2 years ago

i implemented twitter and got this error

TypeError: OAuthStrategy requires a verify callback
    at Strategy.OAuthStrategy (/home/runner/sokobackend/node_modules/passport-oauth1/lib/strategy.js:80:24)
    at new Strategy (/home/runner/sokobackend/node_modules/passport-twitter/lib/strategy.js:53:17)
    at module.exports (/home/runner/sokobackend/config/passport.js:56:16)
    at Object.<anonymous> (/home/runner/sokobackend/index.js:19:29)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)

code

 // import all the things we need  
const GoogleStrategy = require('passport-google-oauth20').Strategy
var TwitterStrategy = require('passport-twitter').Strategy
const mongoose = require('mongoose')
const User = require('../models/User')

module.exports = function(passport) {
  passport.use(
    new GoogleStrategy(
      {
        clientID: process.env.GOOGLE_CLIENT_ID,
        clientSecret: process.env.GOOGLE_CLIENT_SECRET,
        callbackURL: `${process.env.CALLBACK_SCHEME}${process.env.CALLBACK_SUB_DOMAIN}.${process.env.CALLBACK_DOMAIN}/auth/google/callback`,
      },
      async (accessToken, refreshToken, profile, done) => {
        //get the user data from google 
        const newUser = {
          googleId: profile.id,
          displayName: profile.displayName,
          firstName: profile.name.givenName,
          lastName: profile.name.familyName,
          image: profile.photos[0].value,
          email: profile.emails[0].value
        }

        try {
          //find the user in our database 
          let user = await User.findOne({ googleId: profile.id })

          if (user) {
            //If user present in our database.
            done(null, user)
          } else {
            // if user is not preset in our database save user data to database.
            user = await User.create(newUser)
            done(null, user)
          }
        } catch (err) {
          console.error(err)
        }
      }
    )
  )

  // used to serialize the user for the session
  passport.serializeUser((user, done) => {
    done(null, user.id)
  })

  // used to deserialize the user
  passport.deserializeUser((id, done) => {
    User.findById(id, (err, user) => done(err, user))
  })

  passport.use(new TwitterStrategy({
    consumerKey: process.env.TWITTER_API_KEY,
    consumerSecret: process.env.TWITTER_API_SECRET,

    callbackURL: process.env.TWITTER_CALLBACK_URL

  })
)
}
marmooznet commented 1 year ago

did you find the solution?

jman13378 commented 1 year ago

UMM idk if i did I kinda abandoned it