Closed dastageer-eth closed 3 years ago
@KrakenLynch
Looks like we may be working on the same demo project "Secrets"?
I have just implemented this and it is working fine.
Have you installed the NPM package passport-google-oauth20?
Have you inserted: const GoogleStrategy = require('passport-google-oauth20').Strategy;
Happy to take a look at all your code to try and help.
same here, on same demo tutorial. Have you fixed the issue? in my case when i click on Sign in with Google (http://localhost:3000/auth/google) the Google login is not shown. The page is always in loading
solved by using
app.get("/auth/google",
passport.authenticate("google", { scope: ["profile"] });
);
instead of
app.get("/auth/google", function (req, res) {
passport.authenticate("google", { scope: ["profile"] });
});
anyone can explain why the second approach was not working?
solved by using
app.get("/auth/google", passport.authenticate("google", { scope: ["profile"] }); );
instead of
app.get("/auth/google", function (req, res) { passport.authenticate("google", { scope: ["profile"] }); });
anyone can explain why the second approach was not working?
see the documentation its given there
Trying to add Google Login to the Website, I have created Project on Google Developers Console, Created the OAuth Credential and added the Client_ID and Client_Secret to.env file.
Code below :
passport.use( new GoogleStrategy( { clientID: process.env.CLIENT_ID, clientSecret: process.env.CLIENT_SECRET, callbackURL: "http://localhost:3000/auth/google/secrets", userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo", }, function (accessToken, refreshToken, profile, cb) { User.findOrCreate({ googleId: profile.id }, function (err, user) { return cb(err, user); }); } ) );
I have also added the plugin for findorCreate:
const findOrCreate = require("mongoose-findorcreate"); userSchema.plugin(findOrCreate);
callback URL is also proper:
And finally this my get method.
app.get("/auth/google", function (req, res) { passport.authenticate("google", { scope: ["profile"] }); });