How to Use Firebase
LightningAddon supports Firebase as a backend for authentication, database, and server-side flows. This guide walks you through setting it up.
Prerequisites
Step 1: Extension Environment
Add these to envs/.env.development (and envs/.env.production for builds):
VITE_FIREBASE_API_KEY=AIza...
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_STRIPE_PUBLISHABLE_KEY=pk_test_...
VITE_AUTH_PROVIDER=firebase
Get these from Firebase Console → Project Settings → General (Firebase SDK snippet).
Step 2: Server Environment
Create envs/.env.firebase.local for Firebase Cloud Functions:
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=firebase-adminsdk-xxx@your-project.iam.gserviceaccount.com
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n"
STRIPE_API_KEY=sk_test_...
STRIPE_PRICE_ID_MONTHLY=price_...
STRIPE_PRICE_ID_YEARLY=price_...
STRIPE_WEBHOOK_SIGNING_SECRET=whsec_...
- FIREBASE_CLIENT_EMAIL and FIREBASE_PRIVATE_KEY: From Firebase Console → Project Settings → Service Accounts → Generate new private key
- STRIPE_*: From Stripe Dashboard
Step 3: Run Firebase Functions Locally
From the apps/firebase directory:
firebase emulators:start --only functions
Or run individual functions. Ensure envs/.env.firebase.local is loaded (Firebase CLI reads .env in the functions directory if configured).
Step 4: Deploy Cloud Functions
cd apps/firebase
firebase deploy --only functions
Configure Stripe webhook URL in Stripe Dashboard to point to your deployed stripeWebhook function.
What You Get with Firebase
| Feature | Implementation |
|---|---|
| Auth | Firebase Auth (email/password) |
| Database | Firestore (NoSQL) |
| Server logic | Cloud Functions v2 (Node.js) |
| Stripe checkout | stripeCheckout function |
| Stripe portal | stripeManageSubscription function |
| Stripe webhook | stripeWebhook function |
| Session restore | Auth state persisted by Firebase SDK |
Auto-Detection
If you don't set VITE_AUTH_PROVIDER, LightningAddon auto-detects based on which keys are present. If both Supabase and Firebase keys exist, set VITE_AUTH_PROVIDER=firebase explicitly.