So the problem is my app is passing the FCC tests, but when I click on Login with Github then I get the following error:
TypeError: Cannot read property '0' of undefined
at Strategy._verify (/app/app/auth.js:37:40)
at /rbd/pnpm-volume/95184f4b-893d-4eca-a1e1-eba4175d32a6/node_modules/.registry.npmjs.org/passport-oauth2/1.4.0/node_modules/passport-oauth2/lib/strategy.js:193:24
at /rbd/pnpm-volume/95184f4b-893d-4eca-a1e1-eba4175d32a6/node_modules/.registry.npmjs.org/passport-github/1.1.0/node_modules/passport-github/lib/strategy.js:174:7
at passBackControl (/rbd/pnpm-volume/95184f4b-893d-4eca-a1e1-eba4175d32a6/node_modules/.registry.npmjs.org/oauth/0.9.15/node_modules/oauth/lib/oauth2.js:134:9)
at IncomingMessage.<anonymous> (/rbd/pnpm-volume/95184f4b-893d-4eca-a1e1-eba4175d32a6/node_modules/.registry.npmjs.org/oauth/0.9.15/node_modules/oauth/lib/oauth2.js:157:7)
at IncomingMessage.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1094:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
I donât fully understand the error. Is it not connecting to my database?
There were some extra steps that werenât included in the lessons that I did to get it this far:
-Create a new OAuth App on Github. (Right now thereâs 1 user logged in.)
-Create a new database called âchatusersâ on mLab, and given it the user.
-Updated the .env to include the new DATABASE, GITHUBT_CLIENT_ID, and GITHUB-CLIENT-SECRET.
-Include this snippet that allows the tests to pass:
The first line of the error says (/app/app/auth.js:37:40). So I went into my auth.js file, there was this code on line 37: email: profile.emails[0].value || 'No public email',
Thatâs part of the original boilerplate, nothing I added. So I removed the first bit and left with this: email: 'No public email',
Now it works fine, I can authorize my account and was able to finish the rest of the lessons. The chat is working as expected.
So the problem is something to do with profile.emails[0].value. I âthinkâ the problem is either: Github OAuth isnât supplying my email address to the app. Or, itâs not saved in the mLabs database and it throws an error when it tries to look it up.
I had the same problem but in my case after I fix that, in that very same block of code in the last line that reads âreturn cb(null, doc.value);â is giving me another error that says âCannot read property âvalueâ of nullâ, so i just leave âdocâ and then the app ask the authorization and when I allow it, it just redirect me to where I begin and never redirects me to the chat
i have the same problem
since the my code passed the tests and anyway it looks as an outdated setting which is only good as a general example i have decided to let it go, well, considering that to pass one of the earlier glitchy challenges, registration of new users, i had to use a snippet from the forum to cheat the test script with random routing⌠this chapter is really buggy
I ran into this same issue. I solved it however without removing all of profile.emails[0].value⌠If you look at the json youâll see that it returns a key value pair with email: profile.email and not emails: profile.emails[0].value. Use profile.email, it works.
Also ran into another issue with db.collection(...).findOrCreateâŚSays itâs not a function. Use findAndModify instead.
Hope this saves someone some time and aggravation.