Advanced Node and Express - Social Authentication Series (I,II,III) Potential Bug? Username Missing Prop

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,

1 Like

Hello there,

That does make sense. It has been brought up in an issue: Advanced Express - Inconsistent naming of user/username based on local/github Auth type · Issue #39599 · freeCodeCamp/freeCodeCamp

Feel free to join the discussion, and contribute a PR.

1 Like

Awesome, thanks for the link!