Skip to main content

OAuth Providers

The starter kit comes with built-in OAuth support through Better-Auth, allowing users to sign in with various social providers. This guide will help you set up and configure OAuth authentication for your application.

Supported Providers

Default Supported OAuth Providers

Better-Auth includes built-in support for:

  • GitHub
  • Google

For additional providers, see the Better-Auth OAuth documentation

GitHub Authentication

  1. Visit GitHub Developer Settings
  2. Select "OAuth Apps" then "New OAuth App"
  3. Fill in your application details
  4. Copy the generated Client ID and Client Secret
  5. Add them to your .env.local file

The OAuth configuration is managed in :

export const auth = betterAuth({
providers: {
github: {
enabled: true,
clientId: env.GITHUB_CLIENT_ID,
clientSecret: env.GITHUB_CLIENT_SECRET,
}
}
});

Google Authentication

  1. Go to Google Cloud Console
  2. Create a new project or select an existing one
  3. Enable the OAuth2 API
  4. Create OAuth credentials
  5. Add the credentials to your .env.local file

Update :

export const auth = betterAuth({
providers: {
github: {
enabled: true,
// ... github config
},
google: {
enabled: true,
clientId: env.GOOGLE_CLIENT_ID,
clientSecret: env.GOOGLE_CLIENT_SECRET,
}
}
});

Adding Additional Providers

To add more OAuth providers supported by Better-Auth:

  1. Add provider credentials to :
# Provider Name OAuth
PROVIDER_CLIENT_ID=
PROVIDER_CLIENT_SECRET=
  1. Update environment schema in :
export const env = createEnv({
server: {
// ... existing env vars
PROVIDER_CLIENT_ID: z.string().min(1),
PROVIDER_CLIENT_SECRET: z.string().min(1),
}
});
  1. Enable the provider in :
export const auth = betterAuth({
providers: {
// ... existing providers
providerName: {
enabled: true,
clientId: env.PROVIDER_CLIENT_ID,
clientSecret: env.PROVIDER_CLIENT_SECRET,
}
}
});
tip

Check the Better-Auth providers documentation for the complete list of supported providers and their specific configuration requirements.