Social sign-in
Users authenticate through a Facebook account instead of creating a local password.
Better Auth · Const
Better Auth's Facebook provider uses Facebook OAuth credentials configured under socialProviders. Start the client flow with signIn.social({ provider: "facebook" }).
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.
betterAuth({ socialProviders: { facebook: { clientId, clientSecret } } });
authClient.signIn.social({ provider: "facebook" });| Name | Type | Description |
|---|---|---|
provider | string | The social provider identifier; set it to facebook. |
The page demonstrates awaiting the signIn.social call but does not specify a return type.
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.
Users authenticate through a Facebook account instead of creating a local password.
An application requests Facebook permissions beyond the default set.
An application already has a Facebook ID token and wants to use it during sign-in.
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".
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.
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.
socialProviderssignIn.socialclientIdclientSecretscopesidToken