DEV Community

Cover image for How to implement Facebook Login with NestJS

How to implement Facebook Login with NestJS

King Elisha on August 20, 2020

NestJS is a relatively new framework that has been growing in popularity for many good reasons. It has full support for TypeScript and it combines ...
Collapse
 
noorul_amin_d76066b12282 profile image
Noor Ul Amin

when i git the localhost:3000/auth/facebook in the browser i do get a login screen by facebook. After login i do get an error from facebook:
Image description

Collapse
 
hoangdaochuz profile image
hoangdaochuz

I have a similar issue, but I solve it by adding an email scope on facebook app

Image description
I hope this one can help you guys

Collapse
 
tahirmahmudzade profile image
Tahir Mahmudzade

hey did you find the solution for this? I've been getting the exact same error, even though I have tried everything, I'm still stuck with this

Collapse
 
eduwr profile image
Eduardo Wronscki • Edited

you are my hero! Thank you for this article, it was very very useful...

Collapse
 
slavik_semen_be52899bfbcc profile image
Slavik Semen

Thank you.
How protect other routes ?
@Get("/products")
@UseGuards(AuthGuard("facebook")) ?

if i have also Google guard it will be like:
@Get("/products")
@UseGuards(AuthGuard("facebook"))
@UseGuards(AuthGuard("google"))

Collapse
 
yueyuuta profile image
YueYuuta • Edited

I got an error, apparently it does not return the name and email, some help

dev-to-uploads.s3.amazonaws.com/i/...

Collapse
 
usmanashraf678 profile image
Usman Ashraf

I think this shows up if the email of user is not verified.

Collapse
 
embpdaniel profile image
Daniel Montano

Amazing article! One thing to note is if your local front-end runs on a separate port you will have CORS errors with Facebook. To resolve, the front-end MUST use the same port as your server (localhost:3000 in this case) so you'll need to proxy your request made on front-end to get rid of the errors.

Collapse
 
andyogaga1 profile image
Andy Ogaga

Wonderful article Sir....

Collapse
 
quangkhaidev profile image
Đỗ Quang Khải

Thank King Elisha, hope you can create a lot of post like this <3

Collapse
 
budazimbud profile image
BudAzimbud

then how to implement logout ??

Collapse
 
linhtran28 profile image
linhtran28

Thank for your sharing, may i ask how can i implement facebook login with graphql project? is it possible without @Req annotation?

Collapse
 
devlugo profile image
Rodolfo Lugo

Hello @linhtran28 , did you found a way to implemenent this?

Collapse
 
bogdy234 profile image
Filimon Bogdan

Any news on this?

Collapse
 
podrimczech profile image
Faton

To anyone getting the "Sorry, something went wrong". Go to facebook app and allow "email" as a scope.

Collapse
 
gopalesagar profile image
gopalesagar

Good article. I have a question regarding the facebookLoginRedirect function. How are you able to access req.user as req is an Express object?

Collapse
 
hassannazir profile image
hassannazir

I am getting this error:
InternalOAuthError: Failed to obtain access token