Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript Facebook Authentication

Alex Hinson
Alex Hinson
20,184 Points

Facebook 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
Chris Johnson
15,048 Points

Hi 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); } }