Sign users in with Google through a redirect
OAuth browser flow
Better Auth · Const
google is Better Auth’s provider identifier for Google social authentication. Use it in the provider configuration and in social sign-in requests.
google is the provider identifier Better Auth uses to select the Google OAuth configuration. Register the provider under socialProviders.google with its client credentials, then pass provider: "google" to the social sign-in API.
provider: "google"| Name | Type | Description |
|---|---|---|
provider | string | Provider identifier selecting Google; set this to google. |
A social sign-in operation initiated for the configured Google provider.
socialProviders.google and provide both OAuth credentials.signIn.social method.google.import { betterAuth } from "better-auth";
export const auth = betterAuth({
socialProviders: {
google: {
clientId: process.env.GOOGLE_CLIENT_ID as string,
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
},
},
});Configure Google with OAuth credentials, then use the provider identifier google when starting social sign-in.
OAuth browser flow
Multi-platform token validation
Environment-specific deployment
google identifier select?google identifies the Google social-provider configuration in Better Auth. Configure credentials under socialProviders.google, then pass provider: "google" to signIn.social.
Follow-up: How would you support several Google client IDs? The documentation says to pass an array to clientId when accepting ID tokens issued for multiple platforms.
The provider configuration requires the Google OAuth clientId and clientSecret. These values come from a Google Cloud OAuth client, and the callback URI must also be registered there.
Follow-up: What must differ between local and production setup? Register the local callback for development and an application-domain callback for production.
Client-side sign-in uses signIn.social with a request containing provider: "google". Better Auth uses that identifier to route the request to the Google provider.
Follow-up: Can sign-in use a token instead of a redirect? Yes; the Google documentation also describes passing an ID token through signIn.social.
socialProviders.googlesignIn.socialclientIdclientSecretredirectURI