Leave Localhost logoLeave LocalhostDocs
Authentication

Google OAuth

Google OAuth allows users to sign in to your application using their Google accounts.

Google OAuth allows users to sign in to your application using their Google accounts.

Prerequisites

To use Google OAuth, you need to create a project in the Google Cloud Console and obtain a Client ID and Client Secret.

  1. Go to the Google Cloud Console.
  2. Create a new project or select an existing one.
  3. Navigate to APIs & Services > Credentials.
  4. Click Create Credentials and select OAuth client ID.
  5. Configure the OAuth consent screen if you haven't already.
  6. For Application type, select Web application.
  7. Add your application's base URL to Authorized JavaScript origins.
  8. Add the Better Auth callback URL to Authorized redirect URIs. This is typically https://yourdomain.com/api/auth/callback/google.

Environment Variables

Add your Google credentials to your .env (and .env.local) file:

AUTH_GOOGLE_ID=your_google_client_id
AUTH_GOOGLE_SECRET=your_google_client_secret

Configuration

The Google provider is automatically enabled in packages/backend/convex/auth.ts if the environment variables are present:

socialProviders: {
  google: {
    clientId: env.AUTH_GOOGLE_ID,
    clientSecret: env.AUTH_GOOGLE_SECRET,
  },
},

On this page