passport.use(new GoogleStrategy({ clientID: process.env.GOOGLE_AUTH_CLIENT_ID, clientSecret: process.env.GOOGLE_AUTH_CLIENT_SECRET, callbackURL: `${authURL}/auth/google/callback` }, (accessToken, refreshToken, profile, cb) => { if (profile.emails && profile.emails.find(e => e.value.match(new RegExp(`@${process.env.GOOGLE_AUTH_DOMAIN}$`)) && e.verified)) { return cb(null, profile); } return cb(`${profile.emails && profile.emails[0] && profile.emails[0].value} not within @${process.env.GOOGLE_AUTH_DOMAIN}`); }));
passport.use(new GoogleStrategy({ clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: '/auth/google/callback', }, async (accessToken, refreshToken, profile, done) => { let user = await User.findOne({google_id: profile.id}); if (!user) { user = await new User({google_id: profile.id}).save(); } done(null, user); }));
passport.use( new GoogleStrategy( { clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: "/auth/google/callback", proxy: true }, (accessToken, refreshToken, profile, done) => { User.findOne({ googleId: profile.id }).then(existingUser => { if (existingUser) { done(null, existingUser); } else { new User({ googleId: profile.id }) .save() .then(user => done(null, user)); } }); } ) );
}, async (accessToken, refreshToken, profile, done) => { const existingUser = await User.findOne({ providerUniqueID: profile.id, provider: profile.provider }) if (existingUser) { existingUser.providerUniqueID = profile.id; existingUser.profileImageURL= profile._json.picture; existingUser.emailVerified= profile._json.email_verified; existingUser.email= profile._json.email; existingUser.lastName= profile.name.familyName; existingUser.firstName=profile.name.givenName; existingUser.name=profile.displayName; existingUser.accessToken=profile.accessToken; providerUniqueID: profile.id, provider: profile.provider, accessToken, name: profile.displayName, firstName: profile.name.givenName, lastName: profile.name.familyName, email: profile._json.email, emailVerified: profile._json.email_verified, profileImageURL: profile._json.picture
}, (accessToken, refreshToken, profile, done) => { const image = profile.photos[0].value.substring(0, profile.photos[0].value.indexOf('?')) googleID: profile.id, firstName: profile.name.givenName, lastName: profile.name.familyName, email: profile.emails[0].value, image googleID: profile.id }).then(user => { if (user) done(null, user)
passport.use( new GoogleStrategy( { clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken, refreshToken, profile, done) => { User.findOne({ googleId: profile.id }).then((existUser) => { if (existUser) { done(null, existUser) } else { new User({ googleId: profile.id }) .save() .then((user) => done(null, user)) } }) } ) )