Firebase Setup
Connect your Firebase project to Fig1 for user authentication and subscription-based content access.
Overview
Fig1 uses your own Firebase project for authentication. This privacy-first approach means:
- All user data stays in your Firebase project
- Fig1 never stores user PII
- You maintain full control over your users
- Compliant with data protection regulations
Prerequisites
- A Firebase project (console.firebase.google.com)
- Firebase Authentication enabled
- Admin access to your Fig1 site
Step 1: Create a Firebase Project
If you don't have a Firebase project:
- Go to Firebase Console
- Click Add Project
- Enter a project name
- Configure Google Analytics (optional)
- Click Create Project
Step 2: Enable Authentication
- In Firebase Console, select your project
- Go to Build → Authentication
- Click Get Started
- Enable the sign-in methods your app uses (Email/Password, Google, Apple, etc.)
Step 3: Get Web App Configuration
- In Firebase Console, go to Project Settings (gear icon)
- Scroll to Your apps section
- Click Add app → Web (
</>icon) - Register your app with a nickname
- Copy the configuration values:
const firebaseConfig = {
apiKey: "AIzaSy...",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project",
storageBucket: "your-project.appspot.com",
messagingSenderId: "123456789",
appId: "1:123456789:web:abc123..."
};
Step 4: Generate Service Account Key
The service account key allows Fig1 to verify Firebase tokens server-side.
- In Firebase Console, go to Project Settings
- Navigate to Service accounts tab
- Click Generate new private key
- Click Generate key to download the JSON file
- Keep this file secure—it grants admin access to your Firebase project
Security Warning: Never commit this file to version control or expose it publicly.
Step 5: Configure Firebase in Fig1
- Log into Fig1 Dashboard
- Select your site
- Go to Firebase & Subscriptions in the sidebar
- In the Firebase Settings tab, enter your configuration:
Client Configuration
| Field | Description | Example |
|-------|-------------|---------|
| Project ID | Your Firebase project ID | your-project |
| API Key | Web API key | AIzaSy... |
| Auth Domain | Firebase auth domain | your-project.firebaseapp.com |
| App ID | Web app ID | 1:123456789:web:abc123... |
| Storage Bucket | (Optional) Storage bucket | your-project.appspot.com |
| Messaging Sender ID | (Optional) FCM sender ID | 123456789 |
Service Account
Paste the entire contents of your service account JSON file into the Service Account JSON field.
Step 6: Verify Connection
- Click Verify Connection
- You should see a green success message
- If verification fails, check:
- Service account JSON is valid
- Project ID matches your Firebase project
- Firebase Authentication is enabled
Using Firebase Auth in Your App
Initialize Firebase
import { initializeApp } from 'firebase/app';
import { getAuth, signInWithEmailAndPassword } from 'firebase/auth';
const firebaseConfig = {
apiKey: "AIzaSy...",
authDomain: "your-project.firebaseapp.com",
projectId: "your-project",
// ... other config
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
Sign In Users
// Email/Password
await signInWithEmailAndPassword(auth, email, password);
// Get ID token for SDK requests
const user = auth.currentUser;
const token = await user.getIdToken();
Make Authenticated SDK Requests
const response = await fetch('https://app.fig1.ai/api/sdk/content', {
headers: {
'X-Fig1-API-Key': 'your-api-key',
'Authorization': `Bearer ${token}`
}
});
Managing User Subscriptions
Subscriptions are stored in Firebase custom claims. Manage them:
Via Fig1 Dashboard
- Go to Users in the sidebar
- Search for a user
- Click Edit to modify subscriptions
Via Firebase Admin SDK
import * as admin from 'firebase-admin';
await admin.auth().setCustomUserClaims(uid, {
subscriptions: ['boxing_fundamentals', 'premium_content'],
membershipExpiry: '2025-12-31T00:00:00Z'
});
Custom Claims Structure
Fig1 reads these custom claims from Firebase tokens:
{
"membershipTier": "premium",
"subscriptions": ["boxing_fundamentals", "all_access"],
"membershipExpiry": "2025-12-31T00:00:00Z"
}
| Claim | Type | Description |
|-------|------|-------------|
| membershipTier | string | User's tier: free, basic, premium, pro |
| subscriptions | string[] | Array of subscription slugs |
| membershipExpiry | ISO date | When membership expires (optional) |
Security Best Practices
- Protect Service Account Key - Never expose in client-side code
- Validate Tokens Server-Side - Fig1 validates all Firebase tokens
- Use HTTPS - All SDK requests should use HTTPS
- Monitor Firebase Usage - Check Firebase Console for unusual activity
Troubleshooting
"Firebase not configured for this site"
- Ensure you've saved the Firebase configuration
- Check that the service account JSON is valid
"Invalid Firebase token"
- Token may be expired—call
getIdToken(true)to force refresh - Ensure user is signed in before getting token
- Verify the token is from the correct Firebase project
"Failed to verify Firebase connection"
- Double-check Project ID matches exactly
- Ensure service account has required permissions
- Check service account JSON format is valid
Users showing wrong subscriptions
- Firebase tokens are cached—user may need to sign out/in
- Use
getIdToken(true)to force token refresh after subscription changes - Verify custom claims were set correctly in Firebase Console