Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot read property '0' of undefined #35

Open
CallumBrankin opened this issue Aug 23, 2016 · 9 comments
Open

Cannot read property '0' of undefined #35

CallumBrankin opened this issue Aug 23, 2016 · 9 comments

Comments

@CallumBrankin
Copy link

After signing in using facebook, this happens:

C:\Users\callum.PIXELPIN\Documents\facebook\config\passport.js:106
                    newUser.facebook.email = profile.emails[0].value; // facebook can return multiple emails so we'll take
 the first
                                                           ^

TypeError: Cannot read property '0' of undefined
    at Promise.<anonymous> (C:\Users\callum.PIXELPIN\Documents\facebook\config\passport.js:106:60)
    at Promise.<anonymous> (C:\Users\callum.PIXELPIN\Documents\facebook\node_modules\mpromise\lib\promise.js:177:8)
    at emitOne (events.js:96:13)
    at Promise.emit (events.js:188:7)
    at Promise.emit (C:\Users\callum.PIXELPIN\Documents\facebook\node_modules\mpromise\lib\promise.js:84:38)
    at Promise.fulfill (C:\Users\callum.PIXELPIN\Documents\facebook\node_modules\mpromise\lib\promise.js:97:20)
    at Immediate.cb (C:\Users\callum.PIXELPIN\Documents\facebook\node_modules\mongoose\lib\query.js:1153:30)
    at Immediate.<anonymous> (C:\Users\callum.PIXELPIN\Documents\facebook\node_modules\mquery\lib\utils.js:137:16)
    at runCallback (timers.js:574:20)
    at tryOnImmediate (timers.js:554:5)
    at processImmediate [as _immediateCallback] (timers.js:533:5)

@jimmiejackson414-zz
Copy link

I'm having this same issue. All I've seen is something about putting brackets around the email in scope as such: app.get('/auth/facebook', passport.authenticate('facebook', { scope : ['email'] }));

Still didn't quite work for me though, unfortunately.

@deepikaadwani
Copy link

i got these same error can u pls help me E:\easy-node-authentication-facebook\easy-node-authentication-facebook>node serv
er.js
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }

js-bson: Failed to load c++ bson extension, using pure JS version
connect.multipart() will be removed in connect 3.0
visit https://github.com/senchalabs/connect/wiki/Connect-3.0 for alternatives
connect.limit() will be removed in connect 3.0
The magic happens on port 8080
GET / 304 21ms
GET /auth/facebook 302 20ms - 400b
E:\easy-node-authentication-facebook\easy-node-authentication-facebook\config\pa
ssport.js:106
newUser.facebook.email = profile.emails[0].value; // faceboo
k can return multiple emails so we'll take the first
^

TypeError: Cannot read property '0' of undefined
at Promise. (E:\easy-node-authentication-facebook\easy-node-authe
ntication-facebook\config\passport.js:106:60)
at Promise. (E:\easy-node-authentication-facebook\easy-node-authe
ntication-facebook\node_modules\mongoose\node_modules\mpromise\lib\promise.js:17
7:8)
at emitOne (events.js:77:13)
at Promise.emit (events.js:169:7)
at Promise.emit (E:\easy-node-authentication-facebook\easy-node-authenticati
on-facebook\node_modules\mongoose\node_modules\mpromise\lib\promise.js:84:38)
at Promise.fulfill (E:\easy-node-authentication-facebook\easy-node-authentic
ation-facebook\node_modules\mongoose\node_modules\mpromise\lib\promise.js:97:20)

at Immediate.cb (E:\easy-node-authentication-facebook\easy-node-authenticati

on-facebook\node_modules\mongoose\lib\query.js:1153:30)
at Immediate._onImmediate (E:\easy-node-authentication-facebook\easy-node-au
thentication-facebook\node_modules\mongoose\node_modules\mquery\lib\utils.js:137
:16)
at processImmediate [as _immediateCallback] (timers.js:383:17)

@chrisbrainerd
Copy link

chrisbrainerd commented Feb 7, 2017

You need to add in profileFields in the FacebookStrategy, and request emails. Like this:

...
       clientID        : configAuth.facebookAuth.clientID,
        clientSecret    : configAuth.facebookAuth.clientSecret,
        callbackURL     : configAuth.facebookAuth.callbackURL,
        profileFields   : ['emails'],
        passReqToCallback : true // allows us to pass in the req from our route (lets us check if a user is logged in or not)
...

Emails doesn't appear to be a default passed by facebook, so when you add scope: email it asks for emails, but here we actually say we want to use it in this strategy.

@Janusz0
Copy link

Janusz0 commented Feb 8, 2017

Firstly, set your profileFields section.

'facebookAuth' : {
        'clientID'      : 'your App ID',
        'clientSecret'  : 'your App Secret',
        'callbackURL'   : 'your Callback URL',
        'profileFields'   : ['emails']
    }

Now, we need to pull these details wherever we configure our passport code.

passport.use(new FacebookStrategy({

        // pull in our app id and secret from our auth.js file
        clientID        : configAuth.facebookAuth.clientID,
        clientSecret    : configAuth.facebookAuth.clientSecret,
        callbackURL     : configAuth.facebookAuth.callbackURL,
        profileFields   : configAuth.facebookAuth.profileFields

    }

@WORMSS
Copy link

WORMSS commented Feb 8, 2017

@Janusz0 would not supplying the facebookAuth object directly not be the same thing here?

passport.use(new FacebookStrategy(configAuth.facebookAuth);

@Janusz0
Copy link

Janusz0 commented Feb 8, 2017

@WORMSS I guess you can do this way too.

@prdk0
Copy link

prdk0 commented Oct 6, 2018

HI @Janusz0 , I'm having the same problem, my code is like

passport.use(new FacebookStrategy({
    clientID: 'appid',
    clientSecret: 'secret',
    callbackURL: "http://localhost:3000/auth/facebook/callback",
    profileFields: ['id', 'displayName', 'emails']
  },
  function(accessToken, refreshToken, profile, done) {
    User.findOne({facebookId: profile.id}, function(err, user){
        if(err) { return done(err); }
        if(user){
            return done(null, user);
        }else {
            User.findOne({email: profile.emails[0].value}, function(err, user){.......

I'm getting TypeError: Cannot read property '0' of undefined , what to do?
I'm using
"passport": "^0.4.0",
"passport-facebook": "^2.1.1"

@WORMSS
Copy link

WORMSS commented Oct 6, 2018

I thought it's worth noting. You can sign up to Facebook with JUST a phone number, no email

@prdk0
Copy link

prdk0 commented Oct 6, 2018

This jaredhanson/passport-facebook#189 (comment) worked for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants