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
For additional providers, see the Better-Auth OAuth documentation
GitHub Authentication
- Visit GitHub Developer Settings
- Select "OAuth Apps" then "New OAuth App"
- Fill in your application details
- Copy the generated Client ID and Client Secret
- 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
- Go to Google Cloud Console
- Create a new project or select an existing one
- Enable the OAuth2 API
- Create OAuth credentials
- 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:
- Add provider credentials to
:
# Provider Name OAuth
PROVIDER_CLIENT_ID=
PROVIDER_CLIENT_SECRET=
- 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),
}
});
- 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.