Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Facebook Authentication

glenn romaniuk
glenn romaniuk
32,520 Points

node.js passport oauth error "Cannot read property '0' of undefined"

Downloaded the sourcecode for the github authentication. When run i recieve the "Cannot read property '0' of undefined" error. Any ideas?

3 Answers

I had to add scope and it fixed this error.

passport.use(
  new GitHubStrategy(
    {
      clientID: process.env.GITHUB_CLIENT_ID,
      clientSecret: process.env.GITHUB_CLIENT_SECRET,
      callbackURL: 'http://localhost:3000/auth/github/return',
      scope: 'user:email'
    }, generateOrFindUser
  )
);
Valeshan Naidoo
Valeshan Naidoo
27,008 Points

That fixed it for me, other issues I had was the saveUninitialized spelling, and users instead of user for user._id. Long coding sessions like these always leave me rife with silly errors.

Hi,

To solve the problem, go to your GitHub settings page > Profile. And change your "Public email" field from "Don't show my email address" to your email. Save it! That's all :D

Michael Liendo
Michael Liendo
15,326 Points

Hard to tell without looking at your code. I didn't have any trouble when I cloned the repo. Just getting the basics out of the way: You ran npm install?

Where are you getting the error?