mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-01-25 14:18:41 -05:00
2.8 KiB
2.8 KiB
Google OAuth Setup Guide
Prerequisites
- A Google Cloud Platform (GCP) account
- A GCP project with the Google+ API enabled
- OAuth consent screen configured
Step 1: Create OAuth Credentials
- Go to the Google Cloud Console
- Select your project or create a new one
- Navigate to "APIs & Services" > "Credentials"
- Click "Create Credentials" and select "OAuth client ID"
Step 2: Configure OAuth Consent Screen
- If you haven't configured the consent screen, click "Configure Consent Screen"
- Choose "External" user type and click "Create"
- Fill in the required app information:
- App name (e.g., "My App")
- User support email (your email)
- Developer contact information (your email)
- Click "Save and Continue"
- Skip the "Scopes" step (we'll use the default scopes)
- Add test users (your email) if you're in testing mode
- Click "Save and Continue"
Step 3: Create OAuth Client ID
- Go back to "Credentials"
- Click "Create Credentials" > "OAuth client ID"
- Select "Web application" as the application type
- Enter a name (e.g., "Web Client")
- Under "Authorized JavaScript origins", add:
http://localhost:3000http://localhost:3001
- Under "Authorized redirect URIs", add:
http://localhost:3000/api/auth/callback/googlehttp://localhost:3001/api/auth/callback/google
- Click "Create"
Step 4: Set Up Environment Variables
Create or update your .env.local file with the following variables:
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=your-secret-key-here # Generate with: openssl rand -base64 32
GOOGLE_CLIENT_ID=your-google-client-id
GOOGLE_CLIENT_SECRET=your-google-client-secret
DATABASE_URL=file:./dev.db
Step 5: Update Database Schema
Run the following command to update your database schema:
npx prisma db push
Step 6: Restart Your Development Server
npm run dev
Testing Google OAuth
- Visit the login page at
http://localhost:3000/login - Click the "Sign in with Google" button
- You should be redirected to Google's sign-in page
- After signing in, you'll be redirected back to your app
Troubleshooting
- If you get a "redirect_uri_mismatch" error, double-check the Authorized Redirect URIs in your Google Cloud Console
- Make sure the Google+ API is enabled in your GCP project
- Check your browser's console and network tab for any errors
- Ensure your
.env.localfile has the correct values and is in the root of your project
Production Deployment
When deploying to production:
- Update the
NEXTAUTH_URLto your production URL - Add your production domain to the Authorized JavaScript origins and redirect URIs in the Google Cloud Console
- Ensure your production environment has the same environment variables set
- Consider using a more secure database than SQLite for production