Advanced Node and Express: Error when populating user fields

Hey everyone, I want to address an issue in Advanced Node and Express - Implementation of Social Authentication III, copying the code provided by FCC gives me this error when I try to login using Github

TypeError: Cannot read property '0' of undefined
    at Strategy.passport.use.GithubStrategy [as _verify] (/app/server.js:54:38)
    at /rbd/pnpm-volume/e07de6dc-b78e-4eb7-b086-e6e334e59858/node_modules/.registry.npmjs.org/passport-oauth2/1.5.0/node_modules/passport-oauth2/lib/strategy.js:202:24
    at /rbd/pnpm-volume/e07de6dc-b78e-4eb7-b086-e6e334e59858/node_modules/.registry.npmjs.org/passport-github/1.1.0/node_modules/passport-github/lib/strategy.js:174:7
    at passBackControl (/rbd/pnpm-volume/e07de6dc-b78e-4eb7-b086-e6e334e59858/node_modules/.registry.npmjs.org/oauth/0.9.15/node_modules/oauth/lib/oauth2.js:134:9)
    at IncomingMessage.<anonymous> (/rbd/pnpm-volume/e07de6dc-b78e-4eb7-b086-e6e334e59858/node_modules/.registry.npmjs.org/oauth/0.9.15/node_modules/oauth/lib/oauth2.js:157:7)
    at IncomingMessage.emit (events.js:194:15)
    at endReadableNT (_stream_readable.js:1125:12)
    at process._tickCallback (internal/proc

The code:

db.collection('socialusers').findAndModify(
    {id: profile.id},
    {},
    {$setOnInsert:{
        id: profile.id,
        name: profile.displayName || 'John Doe',
        photo: profile.photos[0].value || '',
        email: profile.emails[0].value || 'No public email',
        created_on: new Date(),
        provider: profile.provider || ''
    },$set:{
        last_login: new Date()
    },$inc:{
        login_count: 1
    }},
    {upsert:true, new: true},
    (err, doc) => {
        return cb(null, doc.value);
    }
);

I found that my code errors out cause my Github email is not public so it’s not provided in the profile object
I had to change the email field to email: profile.emails ? profile.emails[0].value : 'No public email',
I think for photo as well, I’m not sure if Github provide a default photo