signIn.social on the client.
Supported providers
The following providers are natively supported and can be configured directly insocialProviders:
For providers not in this list, use the Generic OAuth plugin.
Configure social providers
Add the providers you need to thesocialProviders object in your betterAuth config. Each provider requires a clientId and clientSecret obtained from the provider’s developer console.
auth.ts
Callback URL
The callback URL for each provider follows the pattern:http://localhost:3000 with your app’s domain. For example:
- Google:
https://example.com/api/auth/callback/google - GitHub:
https://example.com/api/auth/callback/github
Sign in with a social provider
CallsignIn.social on the client, specifying the provider:
sign-in.ts
signIn.social redirects the user to the provider’s authorization page. After the user authenticates, they are redirected back to callbackURL.
Sign in with an ID token or access token
If you already have a token from the provider (for example from Google One Tap or a mobile SDK), pass it directly — no redirect occurs:sign-in-id-token.ts
Requesting additional scopes
Specifyscopes in the provider config to request OAuth scopes beyond the defaults:
auth.ts
linkSocial:
request-scopes.ts
Provider-specific options
auth.ts
GitHub
auth.ts
GitHub does not issue refresh tokens for OAuth apps. Access tokens remain valid indefinitely unless explicitly revoked or unused for a year.If you use a GitHub App (not an OAuth App), go to Permissions and Events > Account Permissions > Email Addresses and set it to Read-Only, otherwise you’ll get an
email_not_found error.Custom OAuth providers
For any provider not in the built-in list, use the Generic OAuth plugin:auth.ts