From 6b22e08c2bcb070ba0d9561b9cae7507eb5b94d4 Mon Sep 17 00:00:00 2001 From: Alexander Lyon Date: Fri, 11 Apr 2025 10:42:07 +0100 Subject: [PATCH] feat(facebook): add support for business login using config ids (#1990) --- docs/content/docs/authentication/facebook.mdx | 7 ++++++- packages/better-auth/src/social-providers/facebook.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/content/docs/authentication/facebook.mdx b/docs/content/docs/authentication/facebook.mdx index fc27192e..1837344b 100644 --- a/docs/content/docs/authentication/facebook.mdx +++ b/docs/content/docs/authentication/facebook.mdx @@ -34,9 +34,14 @@ description: Facebook provider setup and usage. }, }) ``` + + + BetterAuth also supports Facebook Login for Business, all you need + to do is provide the `configId` as listed in **Facebook Login For Business > Configurations** alongside your `clientId` and `clientSecret`. Note that the app must be a Business app and, since BetterAuth expects to have an email address and account id, the configuration must be of the "User access token" type. "System-user access token" is not supported. + - ### Sign In with Facebook + ### 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 to `facebook`. diff --git a/packages/better-auth/src/social-providers/facebook.ts b/packages/better-auth/src/social-providers/facebook.ts index b1258bd4..c234f68a 100644 --- a/packages/better-auth/src/social-providers/facebook.ts +++ b/packages/better-auth/src/social-providers/facebook.ts @@ -25,6 +25,11 @@ export interface FacebookOptions extends ProviderOptions { * @default ["id", "name", "email", "picture"] */ fields?: string[]; + + /** + * The config id to use when undergoing oauth + */ + configId?: string; } export const facebook = (options: FacebookOptions) => { @@ -45,6 +50,11 @@ export const facebook = (options: FacebookOptions) => { state, redirectURI, loginHint, + additionalParams: options.configId + ? { + config_id: options.configId, + } + : {}, }); }, validateAuthorizationCode: async ({ code, redirectURI }) => {