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 trialAlex Hinson
20,184 PointsFacebook Login Error
I am getting this error on the website when logging in with Facebook.
Cast to string failed for value "[object Object]" at path "email"
I have copied the code directly over from the project files and it is still showing it. Any thoughts?
1 Answer
Chris Johnson
15,048 PointsHi Alex,
What has happened is that the finished code did not have the value added in for the email so it is looking at the object itself and not the actual email value. I attached the code for the generateOrFindUser method with the value added back in for the email.
Hope this helps.
function generateOrFindUser(accessToken, refreshToken, profile, done){ console.log(profile.emails[0].value); if(profile.emails[0].value) { User.findOneAndUpdate( { email: profile.emails[0].value }, { name: profile.displayName || profile.username, email: profile.emails[0].value, photo: profile.photos[0].value }, { upsert: true }, done ); } else { var noEmailError = new Error("Your email privacy settings prevent you from signing into Bookworm."); done(noEmailError, null); } }