Detect if user is logged in on twitter oauth2 strategy
This commit is contained in:
@ -66,19 +66,32 @@ passport.use(new GitHubStrategy(config.github, function(accessToken, refreshToke
|
|||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
|
|
||||||
passport.use(new TwitterStrategy(config.twitter, function(accessToken, tokenSecret, profile, done) {
|
passport.use(new TwitterStrategy(config.twitter, function(req, accessToken, tokenSecret, profile, done) {
|
||||||
User.findOne({ twitter: profile.id }, function(err, existingUser) {
|
if (req.user) {
|
||||||
if (existingUser) return done(null, existingUser);
|
User.findById(req.user.id, function(err, user) {
|
||||||
var user = new User();
|
user.twitter = profile.id;
|
||||||
user.twitter = profile.id;
|
user.tokens.push({ kind: 'twitter', token: accessToken, tokenSecret: tokenSecret });
|
||||||
user.tokens.push({ kind: 'twitter', token: accessToken, tokenSecret: tokenSecret });
|
user.profile.name = profile.displayName;
|
||||||
user.profile.name = profile.displayName;
|
user.profile.location = user.profile.location || profile._json.location;
|
||||||
user.profile.location = profile._json.location;
|
user.profile.picture = user.profile.picture || profile._json.profile_image_url;
|
||||||
user.profile.picture = profile._json.profile_image_url;
|
user.save(function(err) {
|
||||||
user.save(function(err) {
|
done(err, user);
|
||||||
done(err, user);
|
});
|
||||||
});
|
});
|
||||||
});
|
} else {
|
||||||
|
User.findOne({ twitter: profile.id }, function(err, existingUser) {
|
||||||
|
if (existingUser) return done(null, existingUser);
|
||||||
|
var user = new User();
|
||||||
|
user.twitter = profile.id;
|
||||||
|
user.tokens.push({ kind: 'twitter', token: accessToken, tokenSecret: tokenSecret });
|
||||||
|
user.profile.name = profile.displayName;
|
||||||
|
user.profile.location = profile._json.location;
|
||||||
|
user.profile.picture = profile._json.profile_image_url;
|
||||||
|
user.save(function(err) {
|
||||||
|
done(err, user);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
|
|
||||||
passport.use(new GoogleStrategy(config.google, function(req, accessToken, refreshToken, profile, done) {
|
passport.use(new GoogleStrategy(config.google, function(req, accessToken, refreshToken, profile, done) {
|
||||||
|
Reference in New Issue
Block a user