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

Step 1: Create a Firebase Project

If you don't have a Firebase project:

  1. Go to Firebase Console
  2. Click Add Project
  3. Enter a project name
  4. Configure Google Analytics (optional)
  5. Click Create Project

Step 2: Enable Authentication

  1. In Firebase Console, select your project
  2. Go to Build → Authentication
  3. Click Get Started
  4. Enable the sign-in methods your app uses (Email/Password, Google, Apple, etc.)

Step 3: Get Web App Configuration

  1. In Firebase Console, go to Project Settings (gear icon)
  2. Scroll to Your apps section
  3. Click Add app → Web (</> icon)
  4. Register your app with a nickname
  5. 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.

  1. In Firebase Console, go to Project Settings
  2. Navigate to Service accounts tab
  3. Click Generate new private key
  4. Click Generate key to download the JSON file
  5. 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

  1. Log into Fig1 Dashboard
  2. Select your site
  3. Go to Firebase & Subscriptions in the sidebar
  4. 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

  1. Click Verify Connection
  2. You should see a green success message
  3. 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

  1. Go to Users in the sidebar
  2. Search for a user
  3. 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

  1. Protect Service Account Key - Never expose in client-side code
  2. Validate Tokens Server-Side - Fig1 validates all Firebase tokens
  3. Use HTTPS - All SDK requests should use HTTPS
  4. 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

Next Steps