Socket.IO app is passing tests, but doesn't Authorize?

This is my app:
https://flower-question.glitch.me/

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:

const cors       = require('cors');
app.use(cors());

I’ve gotten this far in the lessons. As I say, the tests pass but the app itself isn’t authorizing:
https://learn.freecodecamp.org/information-security-and-quality-assurance/advanced-node-and-express/set-up-the-environment/

https://learn.freecodecamp.org/information-security-and-quality-assurance/advanced-node-and-express/communicate-by-emitting/

https://learn.freecodecamp.org/information-security-and-quality-assurance/advanced-node-and-express/handle-a-disconnect/

1 Like

I fixed it. err, I got it working at least…

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.

1 Like

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

1 Like

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.

2 Likes

I got the same problem.
I solved it by using mongodb version 3 in the dependencies and changed the way I begin ‘mongo.connect’ to this:

mongo.connect(process.env.DATABASE, (err, client) => {
    var db = client.db('newDB');
1 Like

Thank you TianW22. I have tried all solutions found on the forum and yours was the only one that worked for me!

my test is not passing, and i am getting the error that my app have been blocked by a file extension.

even the simple test add socket.io as a dependency is not passing.

yes this worked for me glacious