5.5 KiB
VIP Coordinator - Technical Documentation
Project Overview
VIP Transportation Coordination System - A web application for managing VIP transportation with driver assignments, real-time tracking, and user management.
Tech Stack
- Frontend: React with TypeScript, Tailwind CSS
- Backend: Node.js with Express, TypeScript
- Database: PostgreSQL
- Authentication: Google OAuth 2.0 via Google Identity Services
- Containerization: Docker & Docker Compose
- State Management: React Context API
- JWT: Custom JWT Key Manager with automatic rotation
Authentication System
Current Implementation (Working)
We use Google Identity Services (GIS) SDK on the frontend to avoid CORS issues:
-
Frontend-First OAuth Flow:
- Frontend loads Google Identity Services SDK
- User clicks "Sign in with Google" button
- Google shows authentication popup
- Google returns a credential (JWT) directly to frontend
- Frontend sends credential to backend
/auth/google/verify - Backend verifies credential, creates/updates user, returns JWT
-
Key Files:
frontend/src/components/GoogleLogin.tsx- Google Sign-In button with GIS SDKbackend/src/routes/simpleAuth.ts- Auth endpoints including/google/verifybackend/src/services/jwtKeyManager.ts- JWT token generation with rotation
-
User Flow:
- First user → Administrator role with status='active'
- Subsequent users → Coordinator role with status='pending'
- Pending users see styled waiting page until admin approval
Important Endpoints
POST /auth/google/verify- Verify Google credential and create/login userGET /auth/me- Get current user from JWT tokenGET /auth/users/me- Get detailed user info including statusGET /auth/setup- Check if system has users
Database Schema
Users Table
users (
id VARCHAR(255) PRIMARY KEY,
google_id VARCHAR(255) UNIQUE,
email VARCHAR(255) UNIQUE NOT NULL,
name VARCHAR(255) NOT NULL,
role VARCHAR(50) CHECK IN ('driver', 'coordinator', 'administrator'),
profile_picture_url TEXT,
status VARCHAR(20) DEFAULT 'pending' CHECK IN ('pending', 'active', 'deactivated'),
approval_status VARCHAR(20) DEFAULT 'pending' CHECK IN ('pending', 'approved', 'denied'),
phone VARCHAR(50),
organization VARCHAR(255),
onboarding_data JSONB,
approved_by VARCHAR(255),
approved_at TIMESTAMP,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
last_login TIMESTAMP,
is_active BOOLEAN DEFAULT true,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
Common Issues & Solutions
1. CORS/Cross-Origin Issues
Problem: OAuth redirects and popups cause CORS errors Solution: Use Google Identity Services SDK directly in frontend, send credential to backend
2. Missing Database Columns
Problem: Backend expects columns that don't exist Solution: Run migrations to add missing columns:
ALTER TABLE users ADD COLUMN IF NOT EXISTS status VARCHAR(20) DEFAULT 'pending';
ALTER TABLE users ADD COLUMN IF NOT EXISTS approval_status VARCHAR(20) DEFAULT 'pending';
3. JWT Token Missing Fields
Problem: Frontend expects fields in JWT that aren't included
Solution: Update jwtKeyManager.ts to include all required fields (status, approval_status, etc.)
4. First User Not Admin
Problem: First user created as coordinator instead of administrator
Solution: Check isFirstUser() method properly counts users in database
5. Auth Routes 404
Problem: Frontend calling wrong API endpoints
Solution: Auth routes are at /auth/* not /api/auth/*
User Management
User Roles
- Administrator: Full access, can approve users, first user gets this role
- Coordinator: Can manage VIPs and drivers, needs admin approval
- Driver: Can view assigned trips, needs admin approval
- Viewer: Read-only access (if implemented)
User Status Flow
- User signs in with Google → Created with status='pending'
- Admin approves → Status changes to 'active'
- Admin can deactivate → Status changes to 'deactivated'
Approval System
- First user is auto-approved as administrator
- All other users need admin approval
- Pending users see a styled waiting page
- Page auto-refreshes every 30 seconds to check approval
Docker Setup
Environment Variables
Create .env file with:
GOOGLE_CLIENT_ID=your-client-id
GOOGLE_CLIENT_SECRET=your-client-secret
GOOGLE_REDIRECT_URI=https://yourdomain.com/auth/google/callback
FRONTEND_URL=https://yourdomain.com
DB_PASSWORD=your-secure-password
Running the System
docker-compose up -d
Services:
- Frontend: http://localhost:5173
- Backend: http://localhost:3000
- PostgreSQL: localhost:5432
- Redis: localhost:6379
Key Learnings
- Google OAuth Strategy: Frontend-first approach with GIS SDK avoids CORS issues entirely
- JWT Management: Custom JWT manager with key rotation provides better security
- Database Migrations: Always check table schema matches backend expectations
- User Experience: Clear, styled feedback for pending users improves perception
- Error Handling: Proper error messages and status codes help debugging
- Docker Warnings: POSTGRES_PASSWORD warnings are cosmetic and don't affect functionality
Future Improvements
- Email notifications when users are approved
- Role-based UI components (hide/show based on user role)
- Audit logging for all admin actions
- Batch user approval interface
- Password-based login as fallback
- User profile editing
- Organization-based access control