Google OAuth Setup for Convex Auth
This guide will help you set up Google OAuth for your Convex Auth implementation.
Prerequisites
- A Google account
- Access to Google Cloud Console
- Your Convex deployment URL
Steps
1. Create a Google Cloud Project
- Go to Google Cloud Console
- Click on the project dropdown (top left)
- Click "New Project"
- Name your project (e.g., "PromptNow Auth")
- Click "Create"
2. Enable Google+ API
- In the Google Cloud Console, go to "APIs & Services" > "Library"
- Search for "Google+ API"
- Click on it and then click "Enable"
3. Create OAuth 2.0 Credentials
-
Go to "APIs & Services" > "Credentials"
-
Click "Create Credentials" > "OAuth client ID"
-
If prompted, configure the OAuth consent screen:
- Choose "External" for user type
- Fill in the required fields:
- App name: "PromptNow" (or your app name)
- User support email: Your email
- Developer contact information: Your email
- Add scopes:
email,profile,openid - Add test users if needed
- Save and continue
-
Back in "Create OAuth client ID":
- Application type: "Web application"
- Name: "PromptNow Web Client"
- Authorized JavaScript origins:
http://localhost:3003(for local development)- Your production URL when deployed
- Authorized redirect URIs:
https://standing-bird-371.convex.site/api/auth/callback/google(replace with your Convex URL)- For local development, you might need to add localhost redirect URIs
- Click "Create"
-
Copy the Client ID and Client Secret
4. Set Environment Variables
In the Convex directory (tools/convex), set the environment variables:
cd tools/convex
npx convex env set AUTH_GOOGLE_ID "your-client-id"
npx convex env set AUTH_GOOGLE_SECRET "your-client-secret"5. Update Convex Dashboard
- Go to your Convex Dashboard
- Navigate to Settings > Environment Variables
- Verify that
AUTH_GOOGLE_IDandAUTH_GOOGLE_SECRETare set
6. Important URLs
Your Google OAuth callback URL will be:
https://[your-convex-deployment].convex.site/api/auth/callback/googleFor the standing-bird-371 deployment:
https://standing-bird-371.convex.site/api/auth/callback/google7. Testing
- Start your development server
- Navigate to the login page
- Click the "Google" button
- You should be redirected to Google's OAuth consent screen
- After authorization, you'll be redirected back to your app
Troubleshooting
Common Issues
-
"redirect_uri_mismatch" error
- Make sure the redirect URI in Google Cloud Console exactly matches your Convex deployment URL
- The format should be:
https://[your-deployment].convex.site/api/auth/callback/google
-
"Invalid client" error
- Double-check that your Client ID and Secret are correctly set in Convex environment variables
- Make sure there are no extra spaces or quotes
-
"Access blocked" error
- Make sure you've configured the OAuth consent screen
- For development, you might need to add test users
Security Notes
- Never commit your Google Client Secret to version control
- Use environment variables for all sensitive credentials
- In production, restrict your OAuth client to specific domains
- Regularly rotate your client secrets