This guide explains how to set up Firebase Authentication for Histora.
✅ Backend Firebase Service: Complete with mock fallback
✅ Frontend Firebase Integration: Enhanced with helper functions
✅ JWT + Firebase Hybrid: Both authentication methods supported
✅ Mock Mode: Development without Firebase configuration
- Go to Firebase Console
- Click "Add project"
- Enter project name:
histora-production - Enable Google Analytics (optional)
- Create project
- In Firebase Console → Authentication
- Click "Get started"
- Go to "Sign-in method" tab
- Enable "Email/Password"
- Optional: Enable Google, GitHub, etc.
- Go to Project Settings → General
- Scroll to "Your apps"
- Click "Web app" icon (</>)
- Register app:
histora-frontend - Copy configuration:
// Add to frontend/.env.local
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key_here
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=histora-production.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=histora-production
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=histora-production.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef123456- Go to Project Settings → Service Accounts
- Click "Generate new private key"
- Download JSON file
- Add to backend configuration:
Option A: Environment Variables
# Add to backend/.env
FIREBASE_PROJECT_ID=histora-production
FIREBASE_PRIVATE_KEY_ID=your_private_key_id
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-abc@histora-production.iam.gserviceaccount.com
FIREBASE_CLIENT_ID=123456789Option B: Service Account File
# Save JSON file as backend/firebase-service-account.json
# Add to backend/.env
FIREBASE_SERVICE_ACCOUNT_PATH=./firebase-service-account.jsonOption C: JSON String
# Add entire JSON as string to backend/.env
FIREBASE_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"histora-production",...}'Currently running in mock mode with these features:
- ✅ Token verification (accepts
firebase-mock-*tokens) - ✅ User creation from Firebase data
- ✅ Custom claims support (mock)
- ✅ Admin SDK functions (mock)
- ✅ Authentication state management
- ✅ Login/signup UI (falls back to JWT)
- ✅ Mock token generation
- ✅ Status checking
# Test Firebase status
curl http://localhost:8000/api/v1/auth/firebase/status
# Test Firebase login (mock)
curl -X POST http://localhost:8000/api/v1/auth/firebase-login \
-H "Content-Type: application/json" \
-d '{"firebase_token":"firebase-mock-test123"}'-
JWT Authentication (Always Available)
- Email/password login
- Admin access
- API authentication
-
Firebase Authentication (When Configured)
- Social login (Google, GitHub, etc.)
- Email verification
- Password reset
- Multi-factor authentication
-
API Key Authentication (Admin Only)
- Backend admin operations
- Development access
graph TD
A[User Registration] --> B{Firebase Configured?}
B -->|Yes| C[Firebase Sign Up]
B -->|No| D[JWT Registration]
C --> E[Get Firebase Token]
E --> F[Send to Backend]
F --> G[Verify Firebase Token]
G --> H[Create/Update User in DB]
H --> I[Return JWT Token]
D --> H
I --> J[User Authenticated]
POST /api/v1/auth/login- JWT loginPOST /api/v1/auth/register- JWT registrationPOST /api/v1/auth/firebase-login- Firebase token loginGET /api/v1/auth/me- Get current userGET /api/v1/auth/health- Auth service statusGET /api/v1/auth/firebase/status- Firebase status
GET /api/v1/auth/admin/users- List usersPOST /api/v1/auth/admin/users- Create userPUT /api/v1/auth/admin/users/{id}- Update userDELETE /api/v1/auth/admin/users/{id}- Deactivate userGET /api/v1/auth/admin/stats- Auth statistics
- ✅ bcrypt password hashing
- ✅ Token expiration (24 hours)
- ✅ Role-based access control
- ✅ Secure secret key
- ✅ Token verification
- ✅ Email verification
- ✅ Custom claims
- ✅ Admin SDK protection
- ✅ Admin API key protection
- ✅ CORS configuration
- ✅ Rate limiting ready
- ✅ Development bypass
# Database
DATABASE_URL=postgresql://user:pass@host:port/db
# JWT
JWT_SECRET_KEY=your_super_secret_jwt_key_here
JWT_EXPIRE_MINUTES=1440
# Admin
ADMIN_API_KEY=your_super_secret_admin_key_here
# Firebase (one of the options above)
FIREBASE_PROJECT_ID=histora-production
# ... other Firebase variables
# Environment
ENVIRONMENT=production
DEBUG=false# API
NEXT_PUBLIC_API_BASE_URL=https://your-backend-url.railway.app
NEXT_PUBLIC_API_VERSION=v1
# Firebase
NEXT_PUBLIC_FIREBASE_API_KEY=your_api_key
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=histora-production.firebaseapp.com
NEXT_PUBLIC_FIREBASE_PROJECT_ID=histora-production
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=histora-production.appspot.com
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=123456789
NEXT_PUBLIC_FIREBASE_APP_ID=1:123456789:web:abcdef123456# Test JWT authentication
npm run test:auth
# Test Firebase integration
npm run test:firebase
# Test admin functions
npm run test:admin# Health check
curl https://your-backend.railway.app/api/v1/auth/health
# Firebase status
curl https://your-backend.railway.app/api/v1/auth/firebase/status- Create Firebase Project (when ready for production)
- Add Social Login Providers (Google, GitHub, Twitter)
- Implement Email Verification
- Add Password Reset Flow
- Set up Analytics (optional)
- Configure Security Rules
- Enable Multi-factor Auth (optional)
- Complete JWT authentication system
- Admin panel with role-based access
- Mock Firebase integration
- User management (CRUD)
- Protected routes
- Multiple auth methods
- Firebase token verification
- User sync between Firebase and database
- Custom claims support
- Social login integration
- Email verification flow
Histora authentication system is production-ready with or without Firebase! 🔥🚀