login with github works if not already registered
This commit is contained in:
parent
ab576fe737
commit
29571e4764
2 changed files with 9 additions and 8 deletions
|
@ -47,12 +47,11 @@ passport.use(new GitHubStrategy({
|
||||||
done(err);
|
done(err);
|
||||||
} else {
|
} else {
|
||||||
User.findById(req.user.id, (err, user) => {
|
User.findById(req.user.id, (err, user) => {
|
||||||
|
user.email = user.email || profile._json.email;
|
||||||
user.github = profile.id;
|
user.github = profile.id;
|
||||||
|
user.username = user.username || profile.username;
|
||||||
user.tokens.push({ kind: 'github', accessToken });
|
user.tokens.push({ kind: 'github', accessToken });
|
||||||
user.profile.name = user.profile.name || profile.displayName;
|
user.name = user.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.save((err) => {
|
user.save((err) => {
|
||||||
req.flash('info', { msg: 'GitHub account has been linked.' });
|
req.flash('info', { msg: 'GitHub account has been linked.' });
|
||||||
done(err, user);
|
done(err, user);
|
||||||
|
@ -73,11 +72,9 @@ passport.use(new GitHubStrategy({
|
||||||
const user = new User();
|
const user = new User();
|
||||||
user.email = profile._json.email;
|
user.email = profile._json.email;
|
||||||
user.github = profile.id;
|
user.github = profile.id;
|
||||||
|
user.username = profile.username;
|
||||||
user.tokens.push({ kind: 'github', accessToken });
|
user.tokens.push({ kind: 'github', accessToken });
|
||||||
user.profile.name = profile.displayName;
|
user.name = profile.displayName;
|
||||||
user.profile.picture = profile._json.avatar_url;
|
|
||||||
user.profile.location = profile._json.location;
|
|
||||||
user.profile.website = profile._json.blog;
|
|
||||||
user.save((err) => {
|
user.save((err) => {
|
||||||
done(err, user);
|
done(err, user);
|
||||||
});
|
});
|
||||||
|
|
|
@ -62,6 +62,10 @@ app.use('/api', aws);
|
||||||
// this is supposed to be TEMPORARY -- until i figure out
|
// this is supposed to be TEMPORARY -- until i figure out
|
||||||
// isomorphic rendering
|
// isomorphic rendering
|
||||||
app.use('/', serverRoutes);
|
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
|
// configure passport
|
||||||
require('./config/passport');
|
require('./config/passport');
|
||||||
|
|
Loading…
Reference in a new issue