Social authentication allows users to login with their existing accounts from Google, GitHub, Facebook, or Apple. No new passwords to remember!
Perfect for: Reducing friction, increasing conversion rates, and providing trusted authentication.
# Add social providers to available methods
NEXT_PUBLIC_AUTH_METHODS="credential,magiclink,google,github"
# Configure each provider (see sections below)
GOOGLE_CLIENT_ID="your-google-client-id"
GOOGLE_CLIENT_SECRET="your-google-secret"Set up OAuth apps with each provider (detailed below).
Social login buttons automatically appear on /[locale]/login and /[locale]/register.
Most popular choice - works for all Gmail users
Setup location: Google Cloud Console
Required scopes: email, profile
http://localhost:3000/api/auth/callback/googlehttps://yourdomain.com/api/auth/callback/googleGOOGLE_CLIENT_ID="123456789.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-google-client-secret"Google setup docs: OAuth 2.0 Setup Guide
http://localhost:3000 (development)http://localhost:3000/api/auth/callback/githubGITHUB_CLIENT_ID="your-github-client-id"
GITHUB_CLIENT_SECRET="your-github-client-secret"GitHub setup docs: Creating an OAuth App
Add redirect URIs in Facebook Login settings:
http://localhost:3000/api/auth/callback/facebookhttps://yourdomain.com/api/auth/callback/facebookFACEBOOK_CLIENT_ID="your-facebook-app-id"
FACEBOOK_CLIENT_SECRET="your-facebook-app-secret"Facebook setup docs: Facebook Login for Web
yourdomain.comhttps://yourdomain.com/api/auth/callback/appleAPPLE_CLIENT_ID="your-apple-service-id"
APPLE_CLIENT_SECRET="your-apple-private-key"Apple requires HTTPS: Apple Sign In only works with HTTPS domains, not localhost. Test in production or use ngrok for development.
Apple setup docs: Sign In with Apple JS
On login/register page, user clicks "Sign in with Google" (or other provider).
User is redirected to provider's authorization page (Google, GitHub, etc.).
User logs into their provider account and grants permissions.
Provider redirects back with user info (email, name, avatar).
Smart account linking: If a user signs up with Google using john@gmail.com, then later tries to login with GitHub using the same email, the accounts are automatically linked.
Account linking features:
The social providers use Better Auth's socialProviders configuration:
// In src/lib/better-auth/auth.ts
socialProviders: {
google: {
prompt: 'select_account',
clientId: env.GOOGLE_CLIENT_ID as string,
clientSecret: env.GOOGLE_CLIENT_SECRET as string,
},
// Add other providers as needed
}Account linking is enabled:
account: {
accountLinking: {
enabled: true,
},
}"Redirect URI mismatch" error?
"Invalid client" or "App not configured" error?
CLIENT_ID and CLIENT_SECRET are correctSocial buttons not appearing?
NEXT_PUBLIC_AUTH_METHODS includes provider nameNEXT_PUBLIC_ prefix where neededBuilt-in security features:
Best practices:
All working? Your users can now login with their favorite social accounts in just one click!