@@ -33,7 +33,7 @@ passport.use(
33
33
callbackURL : `${ API_BASE_URL } /auth/github/callback` ,
34
34
proxy : true
35
35
} ,
36
- function ( accessToken , refreshToken , profile , done ) {
36
+ ( accessToken , refreshToken , profile , done ) => {
37
37
user
38
38
. findOne ( {
39
39
githubId : profile . id
@@ -42,22 +42,27 @@ passport.use(
42
42
if ( currentUser ) {
43
43
console . log ( 'user is: ' , currentUser ) ;
44
44
return done ( null , currentUser ) ;
45
+ }
46
+ let initials ;
47
+ if ( profile . displayName ) {
48
+ initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
45
49
} else {
46
- const initials = profile . displayName . match ( / \b \w / g) . join ( '' ) ;
47
- const nums = profile . id . slice ( 0 , 5 ) ;
48
- user
49
- . create ( {
50
- username : initials + nums + '(Github)' ,
51
- githubId : profile . id
52
- } )
53
- . then ( ( data ) => {
54
- console . log ( 'user added successfully: ' , data ) ;
55
- return done ( null , data ) ;
56
- } )
57
- . catch ( ( data ) =>
58
- console . log ( 'issue with adding user to database' , data )
59
- ) ;
50
+ initials = profile . _json . login . match ( / \b \w / g) . join ( '' ) ;
60
51
}
52
+
53
+ const nums = profile . id . slice ( 0 , 5 ) ;
54
+ user
55
+ . create ( {
56
+ username : initials + nums + '(Github)' ,
57
+ githubId : profile . id
58
+ } )
59
+ . then ( ( data ) => {
60
+ console . log ( 'user added successfully: ' , data ) ;
61
+ return done ( null , data ) ;
62
+ } )
63
+ . catch ( ( data ) =>
64
+ console . log ( 'issue with adding user to database' , data )
65
+ ) ;
61
66
} ) ;
62
67
}
63
68
)
0 commit comments