Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Better Auth · Const

facebook

Better Auth's Facebook provider uses Facebook OAuth credentials configured under socialProviders. Start the client flow with signIn.social({ provider: "facebook" }).

How it works

The Facebook provider is enabled by adding its client ID and secret under the auth instance's socialProviders configuration. Client code starts authentication with signIn.social and identifies Facebook through the provider value; optional scopes or an ID token can customize the flow.

Syntax

betterAuth({ socialProviders: { facebook: { clientId, clientSecret } } });
authClient.signIn.social({ provider: "facebook" });

Parameters

NameTypeDescription
providerstringThe social provider identifier; set it to facebook.

Returns

The page demonstrates awaiting the signIn.social call but does not specify a return type.

Key points

  • Facebook authentication requires both a client ID and a client secret.
  • Create or select the Facebook app in the Facebook Developer Portal to obtain the credentials.
  • Map the Facebook App ID to Better Auth's clientId field.
  • Map the Facebook App Secret to Better Auth's clientSecret field.
  • Register Facebook under the auth instance's socialProviders option.
  • The client sign-in method receives an options object rather than a bare provider string.

Common mistakes

  • The Facebook application's redirect URL must match Better Auth's callback URL during local development.
  • Replace the local callback address with the deployed application's URL in production.
  • Request extra Facebook permissions explicitly through the provider's scopes configuration.

Example: Configure Facebook sign-in

import { betterAuth } from "better-auth"
import { createAuthClient } from "better-auth/client"

export const auth = betterAuth({
  socialProviders: {
    facebook: {
      clientId: process.env.FACEBOOK_CLIENT_ID as string,
      clientSecret: process.env.FACEBOOK_CLIENT_SECRET as string,
    },
  },
})

const authClient = createAuthClient()
await authClient.signIn.social({ provider: "facebook" })

Configure Facebook credentials on the server, then start the Facebook sign-in flow from the client.

When to use it

Social sign-in

Users authenticate through a Facebook account instead of creating a local password.

Additional permissions

An application requests Facebook permissions beyond the default set.

ID-token authentication

An application already has a Facebook ID token and wants to use it during sign-in.

Interview questions

QHow do you configure Facebook in Better Auth?

Add a facebook entry inside socialProviders when creating the Better Auth instance. It requires clientId and clientSecret, typically sourced from environment variables.

Follow-up: How does the client select Facebook? It calls signIn.social with an object whose provider property is set to "facebook".

QHow do you start Facebook sign-in?

Use the client's signIn.social method and pass provider: "facebook". Better Auth then uses the configured Facebook provider for the sign-in flow.

Follow-up: What if the application needs extra Facebook permissions? Configure scopes in the Facebook provider settings.

QWhere do the Facebook credentials come from?

The Facebook Developer Portal provides the credentials: the app's App ID maps to clientId and App Secret maps to clientSecret. The provider configuration reads both values when initializing Better Auth.

Follow-up: What must be configured outside Better Auth? The Facebook app's redirect URL must point to the Better Auth Facebook callback endpoint.

  • socialProviders
  • signIn.social
  • clientId
  • clientSecret
  • scopes
  • idToken

Source: Facebook | Better Auth. Checked 2026-10-15.