passport-facebook
passport-facebook copied to clipboard
keep getting TypeError: Cannot read property '0' of undefined for email
This is the error that I'm getting currently newUser.facebook.email = profile.emails[0].value; ^ TypeError: Cannot read property '0' of undefined
Take a look at the code. (I'm using facebook version v 2.4) https://gist.github.com/arashdoescode/89634453360a8e426690
Probably it is an obvious mistake, hopefully someone experience could point me where is the problem
Cheers!
You do have a misspelling but I don't think you'd be able to compile so I doubt that's the problem -- apssport
. Try using profileFields
as ['emails'
]. I am using emails
and it is working. Also you will want to include displayName
since I see you are using that.
@adam-beck @jaredhanson It is working! for some account but for other accounts it shows the same error newUser.facebook.email = profile.emails[0].value; ^ TypeError: Cannot read property '0' of undefined
Am i missing something here?
@adam-beck @jaredhanson Here is the new file https://gist.github.com/arashdoescode/165a5ca1c4bfdc98f9cd
@adam-beck @jaredhanson some other account email is hidden on facebook, would that be the cause? I just checked that my other account that could authorize , its email is hidden as well. I've been testing this alot of times but seems like there is no luck
Account A - keep showing the same error -->TypeError: Cannot read property '0' of undefined
Account B - Does fetch everything including the email
What did i miss here?
What is your profileFields?
profileFields: ['id', 'name', 'displayName', 'picture.type(large)', 'hometown', 'profileUrl', 'email']
@pateljatin check out this link https://gist.github.com/arashdoescode/165a5ca1c4bfdc98f9cd this is my profileFields
Yep - try "email".
profileFields: ['email']
and then when you access it in your code after auth...use it like so:
email: profile.emails[0].value || null
@pateljatin the weird thing is there are some accounts that works but others don't
I have two facebook accounts to test this out
- First Account does fetched the email
- Second Account return the same error over and over again
I'm not really sure what is issue over here.
in the second account, has user verified their email? facebook will not return email if user hasn't verified their email address.
Then what will it return? The earlier comment said use emails
in profile field you are saying use email
what is correct one?
@SarasArya you can use either one although I think for this module it is preferred to use emails
.
The profile fields get mapped here
@adam-beck I had not confirmed my email id.Hence I wasn't getting it. Thanks for the help.
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
}
Thanks