Enable sign-in with GitHub, Google, or another supported provider.
OAuth login
Better Auth · Pipe
socialProviders configures social login providers in Better Auth. Each provider entry supplies OAuth credentials and can optionally customize redirects, scopes, and profile mapping.
socialProviders is an authentication configuration map whose keys identify providers such as Google or GitHub. Each provider entry supplies OAuth credentials and may also customize callback routing, requested scopes, or profile-to-user mapping.
betterAuth({ socialProviders: { [provider]: { clientId, clientSecret, ...options } } })| Name | Type | Description |
|---|---|---|
socialProviders | Record<string, SocialProviderConfig> | Map of provider names to OAuth configuration objects. |
No standalone return value; this option configures Better Auth's social login providers.
socialProviders option in the Better Auth configuration.clientId identifies the OAuth application registered with the social provider.clientSecret authenticates the server-side application to the OAuth provider.clientKey rather than the usual clientId field.scope to request additional permissions beyond the provider’s defaults.mapProfileToUser when the provider profile needs custom conversion into a Better Auth user.import { betterAuth } from "better-auth";
export const auth = betterAuth({
socialProviders: {
github: {
clientId: process.env.GITHUB_CLIENT_ID!,
clientSecret: process.env.GITHUB_CLIENT_SECRET!,
},
},
});Registers GitHub as an OAuth social provider using credentials supplied through environment variables.
OAuth login
Callback customization
Permission requests
User normalization
socialProviders?socialProviders is an option on the object passed to betterAuth. Its nested keys name providers, and each provider configuration commonly contains clientId and clientSecret.
Follow-up: How can a provider’s OAuth behavior be customized? Add optional settings such as redirectURI, extra scope values, or mapProfileToUser.
The provider key selects the social provider, while the nested values configure that provider. For example, github can contain the GitHub OAuth client ID and secret.
Follow-up: What should be checked if login fails after configuration? Verify the credentials and ensure the callback URI matches the provider registration.
After configuration, the client can invoke signIn.social to begin social authentication. Better Auth also supports authenticating with a provider idToken or accessToken instead of redirecting to the provider.
Follow-up: When might token-based sign-in be useful? It can be used when the application already obtained a provider token and does not need a browser redirect.
signIn.socialclientIdclientSecretclientKeyredirectURIscopemapProfileToUserGeneric OAuth Plugin