-
Notifications
You must be signed in to change notification settings - Fork 0
/
passport_facebook.js
38 lines (37 loc) · 1.13 KB
/
passport_facebook.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
30
31
32
33
34
35
36
37
38
const FacebookStrategy = require('passport-facebook').Strategy
const keys = require('./keys')
const User = require('../models/User_facebook')
module.exports = function(passport){
passport.use(
new FacebookStrategy(
{
clientID: keys.facebookClientID,
clientSecret: keys.facebookClientSecret,
callbackURL: '/auth/facebook/callback'
},
function(accessToken, refreshToken, profile, done) {
console.log(profile)
const newUser = {
username: profile.displayName,
image: "/public/Images/profile.jpeg",
bio: "",
gamesWon: 0,
gamesLost: 0
};
// Check for existing user
User.findOne({
username: profile.displayName
}).then(user => {
if(user){
// Return user
done(null,user)
} else {
// Create user
new User(newUser).save()
.then(user => done(null,user))
}
})
}
)
)
}