Back

Lead Lock: Firebase Setup Guide

Follow this technical guide to configure the Firebase backend for the Structure 1 Digital lead capture system.

Firestore Data Structure
Example document in structure1_leads.
{
  "target_url": "https://example.com",
  "contact_email": "test@example.com",
  "captured_at": "Server Timestamp",
  "status": "new",
  "type": "audit",
  "uid": "anonymous_user_id"
}
Firestore Security Rules
Copy to firestore.rules.
rules_version = '2';

service cloud.firestore {
  match /databases/{database}/documents {
    // Deny all reads and writes by default
    match /{document=**} {
      allow read, write: if false;
    }

    // Allow creating new leads if the user is authenticated anonymously
    // and the data is valid.
    match /structure1_leads/{leadId} {
      allow create: if request.auth != null &&
                       request.resource.data.target_url is string &&
                       request.resource.data.contact_email is string &&
                       request.resource.data.uid == request.auth.uid &&
                       request.resource.data.captured_at == request.time &&
                       request.resource.data.status == 'new' &&
                       request.resource.data.type == 'audit';

      // Disallow any updates, deletes, or reads from the client
      allow read, update, delete: if false;
    }
  }
}
Firebase Console Setup Checklist
A step-by-step guide to configure your Firebase project.
  1. Create Firebase Project
    • Navigate to the Firebase Console.
    • Click "Add project" and follow the on-screen instructions to create a new project.
  2. Enable Firestore
    • In your project, go to Build > Firestore Database.
    • Click "Create database", choose Start in production mode, and select a location.
    • Go to the Rules tab, paste the rules from above, and click "Publish".
  3. Enable Anonymous Authentication
    • Go to Build > Authentication and click "Get started".
    • In the Sign-in method tab, select "Anonymous" from the providers.
    • Enable the toggle and click "Save".
  4. Get Firebase Configuration
    • Click the gear icon for Project settings.
    • Under "Your apps", click the Web icon (</>).
    • Register your app and copy the firebaseConfig object values.
.env.local Configuration
Create this file in your project root and add your Firebase credentials.
# Firebase Configuration
# Get these from your Firebase project settings
NEXT_PUBLIC_FIREBASE_API_KEY=
NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN=
NEXT_PUBLIC_FIREBASE_PROJECT_ID=
NEXT_PUBLIC_FIREBASE_STORAGE_BUCKET=
NEXT_PUBLIC_FIREBASE_MESSAGING_SENDER_ID=
NEXT_PUBLIC_FIREBASE_APP_ID=