- Created Passport Google OAuth 2.0 strategy
- Handles user creation and linking existing users
- Manages user serialization/deserialization
- Added
googleIdfield for Google OAuth users - Made password optional for Google OAuth users
- Updated password hashing logic to skip for Google users
- Added
/api/auth/google- Initiates Google OAuth flow - Added
/api/auth/google/callback- Handles OAuth callback - Redirects to frontend with token and user data
- Imported passport configuration
- Added session middleware for passport
- Added passport initialization
- Created reusable Google logo SVG component
- Matches Google's official branding colors
- Added
googleAuth()method for initiating OAuth - Added
handleGoogleCallback()for processing OAuth response
- Added Google Auth buttons to both login and signup forms
- Added visual dividers ("Or continue with")
- Improved error handling for URL parameters
- Handles OAuth redirect from backend
- Processes token and user data
- Provides loading state during authentication
- Added route for
/auth/google/callback - Imported GoogleCallbackPage component
# Google OAuth Configuration
GOOGLE_CLIENT_ID=your_google_client_id_here
GOOGLE_CLIENT_SECRET=your_google_client_secret_here
GOOGLE_CALLBACK_URL=http://localhost:5000/api/auth/google/callback
# Frontend URL (for redirects after OAuth)
FRONTEND_URL=http://localhost:5173
# Session Secret (for passport sessions)
SESSION_SECRET=your_very_secure_session_secret_here-
Get Google OAuth Credentials:
- Go to Google Cloud Console
- Create/select project
- Enable Google+ API
- Create OAuth 2.0 Client ID
- Add redirect URI:
http://localhost:5000/api/auth/google/callback
-
Add Environment Variables:
- Copy credentials to backend
.envfile - Set FRONTEND_URL and SESSION_SECRET
- Copy credentials to backend
-
Test the Flow:
- Click "Sign in with Google" or "Sign up with Google"
- Complete Google OAuth flow
- Should redirect back and log user in
- ✅ Google OAuth sign-in and sign-up
- ✅ Automatic account linking for existing emails
- ✅ Beautiful Google-branded buttons
- ✅ Seamless user experience
- ✅ Error handling for failed authentication
- ✅ Responsive design
- ✅ Animation and loading states
The implementation follows security best practices and provides a smooth user experience for both new and existing users.