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
| Provider | ID | Documentation |
|---|---|---|
google | console.cloud.google.com | |
| GitHub | github | github.com/settings/developers |
| Discord | discord | discord.com/developers |
| Apple | apple | developer.apple.com |
| Microsoft | microsoft | portal.azure.com |
| Twitter / X | twitter | developer.twitter.com |
facebook | developers.facebook.com | |
linkedin | linkedin.com/developers | |
| Spotify | spotify | developer.spotify.com |
| Twitch | twitch | dev.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
- Go to Google Cloud Console
- Create a new project or select an existing one
- Navigate to APIs & Services → Credentials
- Click Create Credentials → OAuth Client ID
- Select Web application
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google - 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
- Go to GitHub Developer Settings
- Click New OAuth App
- Set Homepage URL to
http://localhost:3000 - Set Authorization callback URL to
http://localhost:3000/api/auth/callback/github - 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"],
},
},
});