Example Docs

Social Sign-on

Better Auth supports 20+ social providers via OAuth 2.0. Users can sign in with a single click — no password required.

Supported Providers

ProviderIDDocumentation
Googlegoogleconsole.cloud.google.com
GitHubgithubgithub.com/settings/developers
Discorddiscorddiscord.com/developers
Appleappledeveloper.apple.com
Microsoftmicrosoftportal.azure.com
Twitter / Xtwitterdeveloper.twitter.com
Facebookfacebookdevelopers.facebook.com
LinkedInlinkedinlinkedin.com/developers
Spotifyspotifydeveloper.spotify.com
Twitchtwitchdev.twitch.tv

Configuration

Server-Side

Add providers to your auth config:

export const auth = betterAuth({
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
    },
    github: {
      clientId: process.env.GITHUB_CLIENT_ID!,
      clientSecret: process.env.GITHUB_CLIENT_SECRET!,
    },
    discord: {
      clientId: process.env.DISCORD_CLIENT_ID!,
      clientSecret: process.env.DISCORD_CLIENT_SECRET!,
    },
  },
});

Client-Side

Trigger social sign-in from your UI:

import { signIn } from "@/lib/auth-client";

function SignInButtons() {
  return (
    <div className="flex flex-col gap-3">
      <button onClick={() => signIn.social({ provider: "google" })}>Continue with Google</button>
      <button onClick={() => signIn.social({ provider: "github" })}>Continue with GitHub</button>
      <button onClick={() => signIn.social({ provider: "discord" })}>Continue with Discord</button>
    </div>
  );
}

Setting Up Google OAuth

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Navigate to APIs & Services → Credentials
  4. Click Create Credentials → OAuth Client ID
  5. Select Web application
  6. Add authorized redirect URI: http://localhost:3000/api/auth/callback/google
  7. Copy the Client ID and Client Secret to your .env
GOOGLE_CLIENT_ID="your-client-id.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-client-secret"

Setting Up GitHub OAuth

  1. Go to GitHub Developer Settings
  2. Click New OAuth App
  3. Set Homepage URL to http://localhost:3000
  4. Set Authorization callback URL to http://localhost:3000/api/auth/callback/github
  5. Copy the Client ID and generate a Client Secret
GITHUB_CLIENT_ID="your-client-id"
GITHUB_CLIENT_SECRET="your-client-secret"

Account Linking

When a user signs in with a social provider and already has an account with the same email, Better Auth automatically links the accounts:

export const auth = betterAuth({
  account: {
    accountLinking: {
      enabled: true,
      trustedProviders: ["google", "github"],
    },
  },
});

Only enable account linking for providers you trust to verify email addresses. This prevents account takeover attacks.

Custom Scopes

Request additional permissions from providers:

export const auth = betterAuth({
  socialProviders: {
    google: {
      clientId: process.env.GOOGLE_CLIENT_ID!,
      clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
      scopes: ["profile", "email", "https://www.googleapis.com/auth/calendar"],
    },
  },
});