Google OAuth Setup Guide
October 28, 2025 ยท View on GitHub
This guide will help you set up Google OAuth authentication for Bitinfrashop.
๐ง Step 1: Google Cloud Console Setup
1.1 Create a Google Cloud Project
- Go to Google Cloud Console
- Click "Select a project" โ "New Project"
- Enter project name:
Bitinfrashop(or your preferred name) - Click "Create"
1.2 Enable Google+ API
- In the Google Cloud Console, go to "APIs & Services" โ "Library"
- Search for "Google+ API" or "Google Identity"
- Click on "Google+ API" and click "Enable"
1.3 Create OAuth 2.0 Credentials
- Go to "APIs & Services" โ "Credentials"
- Click "Create Credentials" โ "OAuth 2.0 Client IDs"
- If prompted, configure the OAuth consent screen:
- Choose "External" user type
- Fill in required fields:
- App name:
Bitinfrashop - User support email: Your email
- Developer contact: Your email
- App name:
- Add scopes:
email,profile,openid - Add test users (your email address)
1.4 Configure OAuth Client
- Application type: "Web application"
- Name:
Bitinfrashop Web Client - Authorized redirect URIs:
- For development:
http://localhost:3000/api/auth/callback/google - For production:
https://yourdomain.com/api/auth/callback/google
- For development:
- Click "Create"
1.5 Get Credentials
- Copy the Client ID and Client Secret
- Keep these secure - you'll need them for environment variables
๐ Step 2: Environment Configuration
2.1 Update .env.local
Add the following to your .env.local file:
# NextAuth.js Configuration
NEXTAUTH_SECRET=your_nextauth_secret_here
NEXTAUTH_URL=http://localhost:3000
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
2.2 Generate NextAuth Secret
Generate a secure secret for NextAuth:
# Option 1: Using Node.js
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
# Option 2: Using OpenSSL
openssl rand -hex 32
# Option 3: Online generator
# Visit: https://generate-secret.vercel.app/32
๐ Step 3: Test the Setup
3.1 Start the Development Server
npm run dev
3.2 Test Google Login
- Go to
http://localhost:3000/login - Click "Continue with Google"
- Complete the Google OAuth flow
- You should be redirected back to the dashboard
๐ Step 4: Production Deployment
4.1 Update OAuth Settings
- Go back to Google Cloud Console โ "Credentials"
- Edit your OAuth 2.0 Client ID
- Add production redirect URI:
https://yourdomain.com/api/auth/callback/google - Update authorized domains if needed
4.2 Environment Variables
Update your production environment variables:
NEXTAUTH_URL=https://yourdomain.com
GOOGLE_CLIENT_ID=your_production_client_id
GOOGLE_CLIENT_SECRET=your_production_client_secret
NEXTAUTH_SECRET=your_production_secret
๐ ๏ธ Troubleshooting
Common Issues
1. "Error 400: redirect_uri_mismatch"
- Cause: Redirect URI doesn't match what's configured in Google Console
- Solution: Ensure redirect URI in Google Console exactly matches your domain
2. "Access blocked: This app's request is invalid"
- Cause: OAuth consent screen not properly configured
- Solution: Complete the OAuth consent screen setup in Google Console
3. "Invalid client" error
- Cause: Wrong Client ID or Client Secret
- Solution: Double-check environment variables match Google Console
4. Database errors after Google login
- Cause: Database schema not updated
- Solution: Run
npx prisma db pushto apply schema changes
Debug Mode
Enable debug mode in development:
NEXTAUTH_DEBUG=true
๐ Additional Resources
๐ Security Notes
- Never commit
.env.localor.envfiles to version control - Use different credentials for development and production
- Rotate secrets regularly in production
- Monitor OAuth usage in Google Cloud Console
- Use HTTPS in production (required by Google OAuth)
Need help? Contact: nodediver@proton.me