Skip to content

Instantly share code, notes, and snippets.

@kp666
Created December 27, 2019 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kp666/b838329891f1652040934399a8297fc7 to your computer and use it in GitHub Desktop.
Save kp666/b838329891f1652040934399a8297fc7 to your computer and use it in GitHub Desktop.
sample.js
app.post('/login', function (req, res, next) {
passport.use(new GoogleStrategy({
clientID: process.env.CLIENT_ID,
clientSecret: process.env.CLIENT_SECRET,
callbackURL: "http://localhost:3000/auth/google/dashboard",
userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo"
},
function(accessToken, refreshToken, profile, cb) {
if(profile._json.hd === "nitc.ac.in"){
User.findOrCreate({ googleId: profile.id ,displayName:profile.displayName,email:profile.emails[0].value}, function (err, user) {
return cb(err, user);
});
}else{
res.redirect('/login_failed');
}
}
))
});;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment