Get your Facebook credentials
To use Facebook sign in, you need a client ID and client Secret. You can get them from the Facebook Developer Portal. Select your app, navigate to App Settings > Basic, locate the following:
- App ID: This is your
clientId
- App Secret: This is your
clientSecret
.
Avoid exposing the clientSecret
in client-side code (e.g., frontend apps) because it’s sensitive information.
Make sure to set the redirect URL to http://localhost:3000/api/auth/callback/facebook
for local development. For production, you should set it to the URL of your application. If you change the base path of the auth routes, you should update the redirect URL accordingly.
Configure the provider
To configure the provider, you need to import the provider and pass it to the socialProviders
option of the auth instance.
Sign In with Facebook
To sign in with Facebook, you can use the signIn.social
function provided by the client. The signIn
function takes an object with the following properties:
provider
: The provider to use. It should be set tofacebook
.
Additional Configuration
Scopes
By default, Facebook provides basic user information. If you need additional permissions, you can specify scopes in your auth configuration:
Additional options:
scopes
: Access basic account information (overwrites).- Default:
"email", "public_profile"
- Default:
fields
: Extend list of fields to retrieve from the Facebook user profile (assignment).- Default:
"id", "name", "email", "picture"
- Default:
Sign In with Facebook With ID or Access Token
To sign in with Facebook using the ID Token, you can use the signIn.social
function to pass the ID Token.
This is useful when you have the ID Token from Facebook on the client-side and want to use it to sign in on the server.
If id token is provided no redirection will happen, and the user will be signed in directly.
For limited login, you need to pass idToken.token
, for only accessToken
you need to pass idToken.accessToken
and idToken.token
together because of (#1183)[https://github.com/better-auth/better-auth/issues/1183].
For a complete list of available permissions, refer to the Permissions Reference.