Integrating of Google Login API in nodejs app

Viewed 6267

Currently I am working on making an e-commerce site using nodejs and mongodb. I want to integrate Google's API on the signup and login pages. Do the experts have any idea about this?

3 Answers

Use the GoogleStrategy of passport.js library. example:

const passport = require('passport');
const { OAuthStrategy: { GoogleStrategy } } = require('passport-google-oauth');

passport.use(new GoogleStrategy({
    consumerKey: GOOGLE_CONSUMER_KEY,
    consumerSecret: GOOGLE_CONSUMER_SECRET,
    callbackURL: "http://www.example.com/auth/google/callback"
  },
  (token, tokenSecret, profile, done) => {
      User.findOrCreate({ googleId: profile.id }, function (err, user) {
        return done(err, user);
      });
  }
));

read docs for more details http://www.passportjs.org/docs/google/

Related