callback url not being executed with google passport strategy oAuth2

305
December 17, 2017, at 3:55 PM

I have tried nearly everything (read threads,searched on google) but i don't understand why is my callback url not being executed.After debugging, i found that the request is being sent to google servers, i get back the profile.But the callback is not being executed.The page just hangs there as soon as i navigate to http:\localhost:3000\auth\google.I am using a localhost server currently. Although the data is being persisted on mongodb which means that the route is working but not the callback.

Below are my routes and local strategy.

AuthRoutes.js

const passport = require("passport");
module.exports = app => {
  app.get("/auth/google/", (req, res) => {
    passport.authenticate("google", {
      scope: ["profile", "email"] 
    });
  });
  app.get(
    "/auth/google/callback",
    passport.authenticate("google", {
      successRedirect: "/profile",
      failureRedirect: "/"
    })
  );
  app.get("/api/current_user", (req, res) => {
    res.send(req.user);
  });
  app.get("/api/logout", (req, res) => {
    req.logout();
    res.redirect("/completed"); 
  });
};

passport.js

const passport = require("passport");
const GoogleStrategy = require("passport-google-oauth20").Strategy;
const keys = require("../config/keys");
const mongoose = require("mongoose");
const User = mongoose.model("users");
passport.serializeUser((user, done) => {
  done(null, user.id); 
});
passport.deserializeUser((id, done) => {
  User.findById(id).then(userModel => {
    done(null, userModel);
  });
});
passport.use(
  new GoogleStrategy(
    {
      clientID: keys.GOOGLE_CLIENT_ID,
      clientSecret: keys.GOOGLE_CLIENT_SECRET,
      callbackURL: "/auth/google/callback",
      proxy: true
    },
    (accessToken, refreshToken, profile, cb) => {
      User.findOne({ googleId: profile.id }).then(existinguser => {
        if (existinguser) {
          //done(null, existinguser);
        } else {
          new User({ googleId: profile.id }).save().then(user => {
            //  done(null, user);
          });
        }
      });
    }
  )
);

Feel free to ask anything that i have missed. Thanks.

Rent Charter Buses Company
READ ALSO
increase consecutively a value synchronously

increase consecutively a value synchronously

I have to update a value in ones of my MongoDB's CollectionsLet's say for example I have a business's collection and I have to increase the consecutive number for every bill made

196
SSML Audio instead of Words

SSML Audio instead of Words

I'm currently new into nodejs, but I've been trying to make an Alexa Skill using the Nodejs Trivia Sample provided on GitHub

289
Can I use two functions to trigger two different documents from cloud firestore?

Can I use two functions to trigger two different documents from cloud firestore?

I have two export functions triggered using Cloud firestore

201
Only query those entries where a ref is not empty in mongoose

Only query those entries where a ref is not empty in mongoose

I have a donate books schema like this:

242