From 29571e4764b2c2af8d34304e9fcec6990747bdcf Mon Sep 17 00:00:00 2001 From: catarak Date: Wed, 31 Aug 2016 12:57:47 -0400 Subject: [PATCH] login with github works if not already registered --- server/config/passport.js | 13 +++++-------- server/server.js | 4 ++++ 2 files changed, 9 insertions(+), 8 deletions(-) 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');