Hi campers,
As part of the Social Authentication series (I, II, and III) in advanced node, I noticed a potential mistake in the guided solution.
If we use the register a user through the local authentication method, the user object returned has a 1) _id, 2) username, and 3)hash password.
We can therefore use the “username” value as a variable to plug into the profile view, “Welcome {username}!”
However, if we login using the social authentication method via Github, the user object returned has the “$setOnInsert” properties.
{
$setOnInsert: {
id: profile.id,
name: profile.displayName || 'John Doe',
photo: profile.photos[0].value || '',
email: Array.isArray(profile.emails)
? profile.emails[0].value
: 'No public email',
created_on: new Date(),
provider: profile.provider || ''
},
This does not have a “username” value, so there is no variable to plug into the profile view, “Welcome {username}!” We get a Welcome (blank)!
I fixed this by adding a property under $setOnInsert:
username: profile.username || 'No username',
So that the profile view shows “Welcome (profile.username)!” , or “Welcome (No username)!” when you get to the profile page via Social Auth.
Let me know if that makes sense.
Thanks,