login with github works if not already registered

This commit is contained in:
catarak 2016-08-31 12:57:47 -04:00
parent ab576fe737
commit 29571e4764
2 changed files with 9 additions and 8 deletions

View File

@ -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);
});

View File

@ -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');