-
Notifications
You must be signed in to change notification settings - Fork 5
/
authStrategy.js
36 lines (28 loc) · 1.03 KB
/
authStrategy.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var passport = require( 'passport' );
var GoogleStrategy = require( 'passport-google-oauth20' ).Strategy;
var Model = require( './db/config' );
var clientID = process.env.GMAIL_CLIENT_ID;
var clientSecret = process.env.GMAIL_CLIENT_SECRET;
module.exports = {
google: new GoogleStrategy({
clientID: clientID,
clientSecret: clientSecret,
callbackURL: process.env.WEBSERVER_URL + '/api/v1/auth/connect/callback/google',
passReqToCallback: true
},
(request, accessToken, refreshToken, profile, done) => {
var userId = profile.emails[0].value;
Model.User.findOrCreate({name: profile.displayName , email: userId}, {access_token: accessToken, refresh_token: refreshToken},
(err, user, created) => {
if (err) {
console.log('err is', err);
done(err, null);
} else {
console.log('user is from Mongo', user);
console.log('created from Mongo is', created);
done(null,user,created);
}
});
}
)
}