Social login
Users authenticate through GitHub instead of creating a local password.
Better Auth · Const
Better Auth's GitHub provider connects OAuth sign-in to a GitHub application. Configure client credentials under socialProviders.github, then invoke signIn.social with provider set to github.
Better Auth enables GitHub by placing the provider credentials under the auth instance's socialProviders configuration. The client then calls signIn.social with provider set to github, which begins the OAuth sign-in flow.
betterAuth({ socialProviders: { github: { clientId, clientSecret } } })
authClient.signIn.social({ provider: "github" })| Name | Type | Description |
|---|---|---|
provider | string | Configured social provider name; for this card it must be github. |
The documentation shows the awaited 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: {
github: {
clientId: process.env.GITHUB_CLIENT_ID as string,
clientSecret: process.env.GITHUB_CLIENT_SECRET as string,
},
},
});
const authClient = createAuthClient();
await authClient.signIn.social({ provider: "github" });Configure GitHub with application credentials, then start the client-side social sign-in flow.
Users authenticate through GitHub instead of creating a local password.
An application needs GitHub identity data while keeping OAuth configuration in Better Auth.
A team enables GitHub sign-in in development before deploying the production callback URL.
Register a GitHub application and provide its client ID and client secret in the github entry of socialProviders. The client can then call signIn.social with provider set to github.
Follow-up: What callback should local development use? Use http://localhost:3000/api/auth/callback/github, while production should use the application's URL.
The provider value identifies which configured social provider starts the flow, so it must be github for this integration. The call is made through the client returned by createAuthClient.
Follow-up: What additional GitHub permission is required? The app must include the user:email scope and grant read-only email access.
The GitHub app needs both a client ID and client secret. These values are passed to Better Auth through environment variables in the provider configuration.
Follow-up: Where are the credentials obtained? They come from the GitHub Developer Portal after creating the application.
socialProviderssignIn.socialcreateAuthClientclientIdclientSecretuser:email