Refactored github strategy
This commit is contained in:
@ -69,19 +69,23 @@ passport.use(new GitHubStrategy({
|
|||||||
},
|
},
|
||||||
function(accessToken, refreshToken, profile, done) {
|
function(accessToken, refreshToken, profile, done) {
|
||||||
User.findOne({ github: profile.id }, function(err, existingUser) {
|
User.findOne({ github: profile.id }, function(err, existingUser) {
|
||||||
if (err) done(err);
|
if (err) return done(err);
|
||||||
if (existingUser) return done(null, existingUser);
|
|
||||||
console.log(profile);
|
if (existingUser) {
|
||||||
|
return done(null, existingUser);
|
||||||
|
}
|
||||||
|
console.log(profile)
|
||||||
var user = new User({
|
var user = new User({
|
||||||
username: profile.username,
|
github: profile.id
|
||||||
displayName: profile.displayName,
|
|
||||||
email: profile.emails[0].value,
|
|
||||||
provider: profile.provider
|
|
||||||
});
|
});
|
||||||
user[profile.provider] = profile.id;
|
user.profile.name = profile.displayName;
|
||||||
|
user.profile.email = profile._json.email;
|
||||||
|
user.profile.picture = profile._json.avatar_url;
|
||||||
|
user.profile.location = profile._json.location;
|
||||||
|
user.profile.website = profile._json.blog;
|
||||||
|
|
||||||
user.save(function(err) {
|
user.save(function(err) {
|
||||||
if (err) console.log(err);
|
done(err, user);
|
||||||
done(null, user);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user