0
votes

When I go to localhost:8000/auth/google, google signup page loads, after signup passport redirects to callbackUrl but without executing the anonymous callback function(accessToken, refreshToken, profile,done). If I console.print accessToken, refreshToken, profile nothing happens.

const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const keys = require('../config/keys')
const mongoose= require('mongoose')
const User = mongoose.model('User')

passport.use(
  new GoogleStrategy({
    clientID: keys.googleClientID,
    clientSecret: keys.googleClientSecret,
    callbackURL: "/auth/google/callback",
    passReqToCallback   : true
  },
  (accessToken, refreshToken, profile,done)=>{
   console.log("allgood",accessToken)
   User.findOne({googleId:profile.id})
   .then((existingUser) => {
     if (existingUser) {

     }else{
       new User({googleId:profile.id}).save();
     }
   })
    })

  )
1

1 Answers

0
votes

Actually the problem was in routes i did not add the following route

app.get('/auth/google/callback',passport.authenticate('google')); 

}

Moreover in passport.use "passReqToCallback : true" is not required.