Nest Authbeta

Facebook OAuth

Sign in with Facebook.

Server config

NestAuthModule.forRoot({
  facebook: {
    appId: process.env.FACEBOOK_APP_ID,
    appSecret: process.env.FACEBOOK_APP_SECRET,
    redirectUri: process.env.FACEBOOK_REDIRECT_URI,
  },
});

Add the optional peer dep:

pnpm add fb

Endpoint

MethodPathBody
POST/auth/login{ providerName: 'facebook', credentials: { token } }

token is the Facebook accessToken from the JS SDK or your popup.

Client call

import { useNestAuth } from '@ackplus/nest-auth-react';
 
function FacebookSignIn() {
  const { login } = useNestAuth();
 
  const handleClick = async () => {
    // Use Facebook's JS SDK to get an access token
    FB.login(async (response) => {
      if (response.authResponse) {
        await login({
          providerName: 'facebook',
          credentials: { token: response.authResponse.accessToken },
        });
      }
    }, { scope: 'email,public_profile' });
  };
 
  return <button onClick={handleClick}>Sign in with Facebook</button>;
}

What the library does

  1. Calls Facebook's Graph API with the access token to fetch the user's profile.
  2. Looks up nest_auth_identities for provider='facebook' + the Facebook user ID.
  3. Creates or links the user, same as Google.

On this page