Skip to content
This repository was archived by the owner on Aug 30, 2021. It is now read-only.

Commit db067bb

Browse files
committed
Infer first and last name from github and twitter response
Last name can contain more than one name. E.g. "John Doe Junior" would have "Doe Junior" as last name.
1 parent 3973595 commit db067bb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

config/strategies/github.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ module.exports = function() {
2323
providerData.refreshToken = refreshToken;
2424

2525
// Create the user OAuth profile
26+
var displayName = profile.displayName.trim();
27+
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
28+
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
29+
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';
30+
2631
var providerUserProfile = {
27-
displayName: profile.displayName,
32+
firstName: firstName,
33+
lastName: lastName,
34+
displayName: displayName,
2835
email: profile.emails[0].value,
2936
username: profile.username,
3037
provider: 'github',

config/strategies/twitter.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ module.exports = function() {
2323
providerData.tokenSecret = tokenSecret;
2424

2525
// Create the user OAuth profile
26+
var displayName = profile.displayName.trim();
27+
var iSpace = displayName.indexOf(' '); // index of the whitespace following the firstName
28+
var firstName = iSpace !== -1 ? displayName.substring(0, iSpace) : displayName;
29+
var lastName = iSpace !== -1 ? displayName.substring(iSpace + 1) : '';
30+
2631
var providerUserProfile = {
27-
displayName: profile.displayName,
32+
firstName: firstName,
33+
lastName: lastName,
34+
displayName: displayName,
2835
username: profile.username,
2936
provider: 'twitter',
3037
providerIdentifierField: 'id_str',

0 commit comments

Comments
 (0)