diff --git a/server/config/passport.js b/server/config/passport.js index cf2dfd81..cccaea88 100644 --- a/server/config/passport.js +++ b/server/config/passport.js @@ -47,12 +47,11 @@ passport.use(new GitHubStrategy({ done(err); } else { User.findById(req.user.id, (err, user) => { + user.email = user.email || profile._json.email; user.github = profile.id; + user.username = user.username || profile.username; user.tokens.push({ kind: 'github', accessToken }); - user.profile.name = user.profile.name || profile.displayName; - user.profile.picture = user.profile.picture || profile._json.avatar_url; - user.profile.location = user.profile.location || profile._json.location; - user.profile.website = user.profile.website || profile._json.blog; + user.name = user.name || profile.displayName; user.save((err) => { req.flash('info', { msg: 'GitHub account has been linked.' }); done(err, user); @@ -73,11 +72,9 @@ passport.use(new GitHubStrategy({ const user = new User(); user.email = profile._json.email; user.github = profile.id; + user.username = profile.username; user.tokens.push({ kind: 'github', accessToken }); - user.profile.name = profile.displayName; - user.profile.picture = profile._json.avatar_url; - user.profile.location = profile._json.location; - user.profile.website = profile._json.blog; + user.name = profile.displayName; user.save((err) => { done(err, user); }); diff --git a/server/server.js b/server/server.js index 22c2c2a5..7cf315da 100644 --- a/server/server.js +++ b/server/server.js @@ -62,6 +62,10 @@ app.use('/api', aws); // this is supposed to be TEMPORARY -- until i figure out // isomorphic rendering app.use('/', serverRoutes); +app.get('/auth/github', passport.authenticate('github')); +app.get('/auth/github/callback', passport.authenticate('github', { failureRedirect: '/login' }), (req, res) => { + res.redirect('/'); +}); // configure passport require('./config/passport');