<<<<<<< HEAD
Firebase Authentication + OTP Setup Guide
This application uses Firebase Authentication for Google sign-in and Brevo for OTP email delivery. Only business email addresses are allowed.
Prerequisites
- Firebase project
- Brevo account (for sending OTP emails)
- Business email domain verification
Step 1: Firebase Setup
1.1 Create Firebase Project
- Go to Firebase Console
- Click "Add project" or select an existing project
- Follow the setup wizard
1.2 Enable Google Authentication
- In Firebase Console, go to Authentication → Sign-in method
- Click on Google provider
- Enable it and set your project support email
- Save the changes
1.3 Get Firebase Web App Configuration
- In Firebase Console, go to Project Settings (gear icon)
- Scroll down to "Your apps" section
- Click the Web icon (
</>) to add a web app - Register your app (you can skip Firebase Hosting for now)
- Copy the Firebase configuration object
1.4 Get Firebase Service Account Key
- In Firebase Console, go to Project Settings → Service accounts
- Click Generate new private key
- Download the JSON file (keep it secure!)
1.5 Set Frontend Environment Variables
Create or update frontend/.env:
VITE_FIREBASE_API_KEY=your-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
VITE_FIREBASE_APP_ID=your-app-id
1.6 Set Backend Environment Variables
You have two options for Firebase Admin SDK:
Option A: Service Account JSON File
FIREBASE_SERVICE_ACCOUNT_KEY=/path/to/service-account-key.json
Option B: Service Account JSON String (Recommended for Docker/Cloud/Hugging Face Spaces)
FIREBASE_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"...","private_key_id":"...","private_key":"...","client_email":"...","client_id":"...","auth_uri":"...","token_uri":"...","auth_provider_x509_cert_url":"...","client_x509_cert_url":"..."}'
For Hugging Face Spaces:
- Use Option B (JSON String) as a Secret (Private)
- Copy the entire contents of your service account JSON file
- Paste it as the value for
FIREBASE_SERVICE_ACCOUNT_JSON - Make sure to keep the single quotes around the JSON if setting via command line, or just paste the raw JSON in the Spaces UI
Step 2: Brevo Setup
2.1 Create Brevo Account
- Go to Brevo (formerly Sendinblue)
- Sign up for a free account (300 emails/day free tier)
- Verify your email address
2.2 Get API Key
- Log in to Brevo
- Go to Settings → API Keys
- Click Generate a new API key
- Copy the API key (starts with
xkeysib-...)
2.3 Verify Sender Email
- Go to Senders & IP → Senders
- Click Add a sender
- Enter your sender email (e.g.,
noreply@yourdomain.com) - Verify the email address (check your inbox for verification email)
- Once verified, you can use it to send emails
2.4 Set Backend Environment Variables
BREVO_API_KEY=xkeysib-your-api-key-here
BREVO_SENDER_EMAIL=noreply@yourdomain.com
BREVO_SENDER_NAME=EZOFIS AI
Step 3: JWT Secret Key
Generate a strong random string for JWT token signing:
# Generate a random secret (Linux/Mac)
openssl rand -hex 32
# Or use Python
python -c "import secrets; print(secrets.token_hex(32))"
Set the environment variable:
JWT_SECRET_KEY=your-generated-secret-key-here
Step 4: Frontend URL
Set the frontend URL for OAuth redirects:
FRONTEND_URL=http://localhost:5173 # Development
# OR
FRONTEND_URL=https://your-domain.com # Production
Step 5: Install Dependencies
Backend
cd backend
pip install -r requirements.txt
Frontend
cd frontend
npm install
Step 6: Database Migration
The database will automatically create the new schema when you start the application. However, if you have existing data:
Option 1: Fresh Start (Recommended for Development)
- Delete the existing database file:
data/app.db - Restart the application (tables will be recreated)
Option 2: Manual Migration (For Production)
- The new
userstable will be created automatically - Existing
extractionstable needsuser_idcolumn added - You'll need to assign existing records to a default user or migrate them
Step 7: Test the Setup
7.1 Test Firebase Authentication
- Start the backend server
- Start the frontend development server
- Navigate to the application
- Click "Google Sign In"
- Sign in with a business Google account
- Verify you're redirected to the dashboard
7.2 Test OTP Authentication
- Click on "Email / OTP" tab
- Enter a business email address
- Click "Send OTP"
- Check your email for the OTP code
- Enter the OTP and verify
- Verify you're redirected to the dashboard
7.3 Test Business Email Validation
- Try to sign in with a personal Gmail account
- Verify you get an error message
- Try OTP with a personal email
- Verify it's blocked
Environment Variables Summary
Backend (.env or environment)
# Firebase
FIREBASE_SERVICE_ACCOUNT_JSON='{...}' # OR
FIREBASE_SERVICE_ACCOUNT_KEY=/path/to/key.json
# Brevo
BREVO_API_KEY=xkeysib-...
BREVO_SENDER_EMAIL=noreply@yourdomain.com
BREVO_SENDER_NAME=EZOFIS AI
# JWT
JWT_SECRET_KEY=your-secret-key
# Frontend URL
FRONTEND_URL=http://localhost:5173 # For local development
# For Hugging Face Spaces: https://your-username-ezofisocr.hf.space
For Hugging Face Spaces:
- Set
FIREBASE_SERVICE_ACCOUNT_JSON,BREVO_API_KEY, andJWT_SECRET_KEYas Secrets (Private) - Set
BREVO_SENDER_EMAIL,BREVO_SENDER_NAME, andFRONTEND_URLas Variables (Public) - See
HUGGINGFACE_SPACES_SETUP.mdfor detailed instructions
Frontend (.env)
VITE_FIREBASE_API_KEY=...
VITE_FIREBASE_AUTH_DOMAIN=...
VITE_FIREBASE_PROJECT_ID=...
VITE_FIREBASE_STORAGE_BUCKET=...
VITE_FIREBASE_MESSAGING_SENDER_ID=...
VITE_FIREBASE_APP_ID=...
VITE_API_BASE_URL=http://localhost:7860
Troubleshooting
Firebase Issues
- "Firebase not configured": Check that
FIREBASE_SERVICE_ACCOUNT_JSONorFIREBASE_SERVICE_ACCOUNT_KEYis set correctly - "Invalid Firebase token": Ensure Firebase Web SDK is properly configured in frontend
- "Email not found": Make sure Google sign-in is enabled in Firebase Console
Brevo Issues
- "Failed to send email":
- Verify your API key is correct
- Check that sender email is verified in Brevo
- Ensure you haven't exceeded the free tier limit (300 emails/day)
- "API key not set": Check that
BREVO_API_KEYenvironment variable is set
Business Email Validation
- Personal emails (Gmail, Yahoo, etc.) are automatically blocked
- Only business/corporate email domains are allowed
- The validation happens on both frontend and backend
Security Notes
- Never commit Firebase service account keys or API keys to version control
- Use environment variables or secure secret management
- JWT tokens expire after 7 days
- OTP codes expire after 10 minutes
- Maximum 5 OTP verification attempts per email
- All extraction records are filtered by user_id for data isolation
Production Deployment
- Set all environment variables in your hosting platform
- Use HTTPS for both frontend and backend
- Update
FRONTEND_URLto your production domain - Verify sender email in Brevo with your production domain
- Consider using Redis for OTP storage instead of in-memory (for scalability)
- Set up proper error monitoring and logging
Support
For issues:
- Firebase: Firebase Documentation
- Brevo: Brevo API Documentation
=======
Firebase Authentication + OTP Setup Guide
This application uses Firebase Authentication for Google sign-in and Brevo for OTP email delivery. Only business email addresses are allowed.
Prerequisites
- Firebase project
- Brevo account (for sending OTP emails)
- Business email domain verification
Step 1: Firebase Setup
1.1 Create Firebase Project
- Go to Firebase Console
- Click "Add project" or select an existing project
- Follow the setup wizard
1.2 Enable Google Authentication
- In Firebase Console, go to Authentication → Sign-in method
- Click on Google provider
- Enable it and set your project support email
- Save the changes
1.3 Get Firebase Web App Configuration
- In Firebase Console, go to Project Settings (gear icon)
- Scroll down to "Your apps" section
- Click the Web icon (
</>) to add a web app - Register your app (you can skip Firebase Hosting for now)
- Copy the Firebase configuration object
1.4 Get Firebase Service Account Key
- In Firebase Console, go to Project Settings → Service accounts
- Click Generate new private key
- Download the JSON file (keep it secure!)
1.5 Set Frontend Environment Variables
Create or update frontend/.env:
VITE_FIREBASE_API_KEY=your-api-key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=your-sender-id
VITE_FIREBASE_APP_ID=your-app-id
1.6 Set Backend Environment Variables
You have two options for Firebase Admin SDK:
Option A: Service Account JSON File
FIREBASE_SERVICE_ACCOUNT_KEY=/path/to/service-account-key.json
Option B: Service Account JSON String (Recommended for Docker/Cloud)
FIREBASE_SERVICE_ACCOUNT_JSON='{"type":"service_account","project_id":"...","private_key_id":"...","private_key":"...","client_email":"...","client_id":"...","auth_uri":"...","token_uri":"...","auth_provider_x509_cert_url":"...","client_x509_cert_url":"..."}'
Step 2: Brevo Setup
2.1 Create Brevo Account
- Go to Brevo (formerly Sendinblue)
- Sign up for a free account (300 emails/day free tier)
- Verify your email address
2.2 Get API Key
- Log in to Brevo
- Go to Settings → API Keys
- Click Generate a new API key
- Copy the API key (starts with
xkeysib-...)
2.3 Verify Sender Email
- Go to Senders & IP → Senders
- Click Add a sender
- Enter your sender email (e.g.,
noreply@yourdomain.com) - Verify the email address (check your inbox for verification email)
- Once verified, you can use it to send emails
2.4 Set Backend Environment Variables
BREVO_API_KEY=xkeysib-your-api-key-here
BREVO_SENDER_EMAIL=noreply@yourdomain.com
BREVO_SENDER_NAME=EZOFIS AI
Step 3: JWT Secret Key
Generate a strong random string for JWT token signing:
# Generate a random secret (Linux/Mac)
openssl rand -hex 32
# Or use Python
python -c "import secrets; print(secrets.token_hex(32))"
Set the environment variable:
JWT_SECRET_KEY=your-generated-secret-key-here
Step 4: Frontend URL
Set the frontend URL for OAuth redirects:
FRONTEND_URL=http://localhost:5173 # Development
# OR
FRONTEND_URL=https://your-domain.com # Production
Step 5: Install Dependencies
Backend
cd backend
pip install -r requirements.txt
Frontend
cd frontend
npm install
Step 6: Database Migration
The database will automatically create the new schema when you start the application. However, if you have existing data:
Option 1: Fresh Start (Recommended for Development)
- Delete the existing database file:
data/app.db - Restart the application (tables will be recreated)
Option 2: Manual Migration (For Production)
- The new
userstable will be created automatically - Existing
extractionstable needsuser_idcolumn added - You'll need to assign existing records to a default user or migrate them
Step 7: Test the Setup
7.1 Test Firebase Authentication
- Start the backend server
- Start the frontend development server
- Navigate to the application
- Click "Google Sign In"
- Sign in with a business Google account
- Verify you're redirected to the dashboard
7.2 Test OTP Authentication
- Click on "Email / OTP" tab
- Enter a business email address
- Click "Send OTP"
- Check your email for the OTP code
- Enter the OTP and verify
- Verify you're redirected to the dashboard
7.3 Test Business Email Validation
- Try to sign in with a personal Gmail account
- Verify you get an error message
- Try OTP with a personal email
- Verify it's blocked
Environment Variables Summary
Backend (.env or environment)
# Firebase
FIREBASE_SERVICE_ACCOUNT_JSON='{...}' # OR
FIREBASE_SERVICE_ACCOUNT_KEY=/path/to/key.json
# Brevo
BREVO_API_KEY=xkeysib-...
BREVO_SENDER_EMAIL=noreply@yourdomain.com
BREVO_SENDER_NAME=EZOFIS AI
# JWT
JWT_SECRET_KEY=your-secret-key
# Frontend URL
FRONTEND_URL=http://localhost:5173
Frontend (.env)
VITE_FIREBASE_API_KEY=...
VITE_FIREBASE_AUTH_DOMAIN=...
VITE_FIREBASE_PROJECT_ID=...
VITE_FIREBASE_STORAGE_BUCKET=...
VITE_FIREBASE_MESSAGING_SENDER_ID=...
VITE_FIREBASE_APP_ID=...
VITE_API_BASE_URL=http://localhost:7860
Troubleshooting
Firebase Issues
- "Firebase not configured": Check that
FIREBASE_SERVICE_ACCOUNT_JSONorFIREBASE_SERVICE_ACCOUNT_KEYis set correctly - "Invalid Firebase token": Ensure Firebase Web SDK is properly configured in frontend
- "Email not found": Make sure Google sign-in is enabled in Firebase Console
Brevo Issues
- "Failed to send email":
- Verify your API key is correct
- Check that sender email is verified in Brevo
- Ensure you haven't exceeded the free tier limit (300 emails/day)
- "API key not set": Check that
BREVO_API_KEYenvironment variable is set
Business Email Validation
- Personal emails (Gmail, Yahoo, etc.) are automatically blocked
- Only business/corporate email domains are allowed
- The validation happens on both frontend and backend
Security Notes
- Never commit Firebase service account keys or API keys to version control
- Use environment variables or secure secret management
- JWT tokens expire after 7 days
- OTP codes expire after 10 minutes
- Maximum 5 OTP verification attempts per email
- All extraction records are filtered by user_id for data isolation
Production Deployment
- Set all environment variables in your hosting platform
- Use HTTPS for both frontend and backend
- Update
FRONTEND_URLto your production domain - Verify sender email in Brevo with your production domain
- Consider using Redis for OTP storage instead of in-memory (for scalability)
- Set up proper error monitoring and logging
Support
For issues:
- Firebase: Firebase Documentation
- Brevo: Brevo API Documentation
daae7a900bd14d0802e4f04b99edb85493053f1d