Google OAuth Setup Guide
This guide explains how to configure Google OAuth for user registration and login in STEMBlock.ai.
Overview
STEMBlock.ai supports registration and login using existing Google accounts. This allows users (especially students and coaches) to quickly sign up and access the platform using their school or personal Google accounts.
Prerequisites
- Google Cloud Platform account
- Access to Google Cloud Console
- Admin access to STEMBlock.ai backend
Part 1: Google Cloud Platform Setup
Step 1: Create a Google Cloud Project
- Navigate to Google Cloud Console
- Click on the project dropdown at the top of the page
- Click "New Project"
- Enter project details:
- Project Name:
STEMBlock-Production(or your preferred name) - Organization: Select your organization (if applicable)
- Project Name:
- Click "Create"
Step 2: Enable Google+ API
- In the Google Cloud Console, go to APIs & Services > Library
- Search for "Google+ API"
- Click on "Google+ API"
- Click "Enable"
Step 3: Configure OAuth Consent Screen
-
Go to APIs & Services > OAuth consent screen
-
Select User Type:
- Internal: If using Google Workspace (recommended for schools)
- External: If allowing any Google account
-
Click "Create"
-
Fill in the OAuth consent screen form:
- App name:
STEMBlock.ai - User support email: Your support email
- App logo: Upload STEMBlock.ai logo (optional)
- Application home page:
http://localhost:3000(for development) or your production URL - Authorized domains: Add
localhostfor development - Developer contact information: Your email address
- App name:
-
Click "Save and Continue"
-
Scopes (Step 2):
- Click "Add or Remove Scopes"
- Select the following scopes:
openidprofileemail
- Click "Update"
- Click "Save and Continue"
-
Test users (Step 3) - for External apps only:
- Add test user email addresses that can access the app during development
- Click "Save and Continue"
-
Summary (Step 4):
- Review your settings
- Click "Back to Dashboard"
Step 4: Create OAuth 2.0 Credentials
-
Go to APIs & Services > Credentials
-
Click "Create Credentials" → "OAuth client ID"
-
Select Application type: "Web application"
-
Configure the web client:
- Name:
STEMBlock Web Client - Authorized JavaScript origins:
http://localhost:3000(development)https://your-production-domain.com(production)
- Authorized redirect URIs:
http://localhost:3001/auth/google/callback(development)https://your-api-domain.com/auth/google/callback(production)
- Name:
-
Click "Create"
-
Save your credentials:
- Copy the Client ID
- Copy the Client Secret
- Store these securely (you'll need them for backend configuration)
Part 2: Backend Configuration
Step 1: Update Environment Variables
Add the following to your backend/.env file:
# Google OAuth Configuration
GOOGLE_CLIENT_ID="your-client-id-here.apps.googleusercontent.com"
GOOGLE_CLIENT_SECRET="your-client-secret-here"
GOOGLE_REDIRECT_URI="http://localhost:3001/auth/google/callback"
# For production, use your production URL:
# GOOGLE_REDIRECT_URI="https://api.stemblock.ai/auth/google/callback"
Step 2: Restart Backend
After adding environment variables, restart the backend:
cd backend
npm run start:dev
You should see a log message indicating Google OAuth is configured.
Testing Google OAuth
Test Registration Flow
- Start both backend and frontend servers
- Navigate to http://localhost:3000/register
- Click "Continue with Google"
- You should be redirected to Google's OAuth consent page
- Select a Google account
- Grant permissions to STEMBlock.ai
- Complete the registration form (role, name, etc.)
- Click "Register"
- You should be redirected to the appropriate dashboard
Test Login Flow
- Navigate to http://localhost:3000/login
- Click "Continue with Google"
- Select your Google account (already registered)
- You should be automatically logged in
Troubleshooting
Issue: "Error 400: redirect_uri_mismatch"
Solution:
- Verify the redirect URI in Google Cloud Console matches exactly what's in your
.envfile - Check for trailing slashes (they must match exactly)
- Ensure you're using the correct protocol (http vs https)
Issue: "Google OAuth not configured" warning
Solution:
- Verify
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRETare set in.env - Restart the backend server
- Check for typos in environment variable names
Security Best Practices
- Never commit credentials: Add
.envto.gitignore - Use environment-specific credentials: Different credentials for dev/staging/production
- Rotate secrets regularly: Update Client Secret periodically
- Use HTTPS in production: Never use HTTP for OAuth in production
Last Updated: November 3, 2025