Databutton
DiscordSign up
  • Getting Started
    • Databutton University
    • Meet the Databutton AI agent
  • Help & FAQ
  • Prompting in Databutton
    • Top prompting strategies
    • Prompting app UI & design
    • Prompting up your backend (APIs)
    • Troubleshooting prompt
    • Connecting UI with the Backend
    • Prompt Gallery
  • Using Tasks
    • How to use tasks in Databutton
    • Writing a good task
    • Chaining tasks
  • Task Gallery
  • Integrating SaaS Services
    • Authentication Integration
      • Firebase Integration
      • Supabase Integration
    • Working with Firestore Database
    • Working with Supabase Table
    • Stripe Integration
  • App Configurations
    • Package Installations
    • Managing Secrets
    • Customising Agent Behavior
    • Invite Collaborators
    • Opening Dev APIs
    • Customising App Design
  • Tutorials
    • Configuring a custom domain for your app
  • Databutton MCP – Build tools for AI
  • Troubleshooting
    • Browser window crashes
Powered by GitBook
On this page
  • Prerequisites
  • Firestore Database Integration Steps
  • Step 1: Enable Firestore Database
  • Step 2: Prepare your App for Firestore Integration
  • Setp 3: Updating Security Rules in Firebase
  • Step 4: Test and Confirm Firestore Integration
  • Master Prompt to Guide the Agent for Integration

Was this helpful?

  1. Integrating SaaS Services

Working with Firestore Database

Adding user Data to Firestore Database.

PreviousSupabase IntegrationNextWorking with Supabase Table

Last updated 3 months ago

Was this helpful?

Prerequisites

Before you begin, ensure the following are ready

  • Firebase Project: Set up your Firebase project in the .

    This will serve as the foundation for enabling Firestore in your app.

  • Authentication: Enable authentication for your app to control access.

    For detailed guidance, check out the

You can read more about how to set up Firebase Authentication in Databutton .

Firestore Database Integration Steps

You can watch this video to follow the step by step Firestore database integration.

Step 1: Enable Firestore Database

  • Go to the Firebase Console and select your project.

    This is the main control panel for all Firebase services.

  • Go to "Firestore Database" in the Firebase Console's left sidebar.

    This is where you manage your database setup.

  • If not created, click "Create Database" and select a starting mode.

    Select the Firestore location (pick a location close to your users for optimal performance) and Choose between "Test mode" or "Production mode." Starting with "Test" mode is recommended.

Test Mode vs Production Mode : In Test Mode, security rules are more relaxed, making it easier to test your setup. Wheras, in Production Mode, you’ll need to configure stricter security rules.


Step 2: Prepare your App for Firestore Integration

  • Plan Your Data Structure

    Firestore is schema-flexible, meaning it doesn’t enforce a fixed structure. Planning your data structure upfront ensures consistency and scalability.

    • Identify collections and documents you’ll need.

    • Consider relationships, such as linking Orders to Customers or Users

  • Define the Data You Need to Store

    Think about the specific data your app will handle and organize it logically.

Example: Business App to Store Customer Details

  • Collection: Customers

    • Fields: name, email, phone, signup_date, last_login, etc.

  • Collection (Optional): Orders

    • Fields: customer_id, order_date, order_details.

Prompt Example:

You can add the following prompt over your active task :

Hi there! I’m building a business app to manage customer details. Could you help me to set up a Firebas Database via the FRONTEND only:  
- Suggest a Firestore data structure to store customer details (e.g., name, email, phone, signup date).  
- If relevant, include additional collections like orders tied to customers.  
- Provide a Markdown representation of the data structure.  
- Don't write any code. Let's first go through the Database structure first. 

Alternatively, prompt the Agent for Data Structure Suggestions;

Hi there! I’ve set up Firestore Datastore and Firebase authentication.  
Please help me set up a Firestore Database via the FRONTEND only:  
- Suggest an optimal data structure for my project based on the current UI and app details.  
- Provide a Markdown representation of the structure.  
- Generate permissive security rules to allow access only for authenticated users.  
- Don't write any code. Let’s first go through the database structure before discussing rules.  

Setp 3: Updating Security Rules in Firebase

Follow-Up Prompt for Security Rules : Use this prompt to request less strict security rules for initial testing.

Based on the suggested Firestore data structure, please generate permissive security rules:  
- Allow read and write access for authenticated users only.  
- Keep the rules minimally strict to simplify testing.  
- Avoid overly restrictive configurations unless absolutely necessary.  

Agent Output Example:

rules_version = '2';
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if request.auth != null;
    }
  }
}

Copy these rules into the Firebase Console under the Firestore Rules tab.

Hit the Develop & Test button to validate the rules.


Step 4: Test and Confirm Firestore Integration

After deploying the rules, validate your Firestore setup by testing basic operations:

  • Testing Access

    Confirm that authenticated users can interact with the database as intended.

    • Test adding a record to a collection

    • Verify that unauthorized access is restricted as expected.

Prompt Suggestions:

Implementation

I’ve deployed the suggested Firestore security rules. 
Can you proceed for the implementation via the Frontend Only. 
 

Testing

Click the "Test Connection" button to test your Firestore integration.


Master Prompt to Guide the Agent for Integration

Updated Master Prompt for Full Integration:

Hi there! I’ve enabled Firestore Datastore and set up Firebase authentication.  
I’d like to integrate Firestore Datastore into my project with the following requirements:

1. Data Structure Confirmation:
   - Analyze the existing data structure in the relevant UI files.  
   - Provide a clear Markdown representation of the data structure before proceeding.  

2. Security Rules:
   - Generate permissive security rules that allow access only for authenticated users.  
   - Guide me step by step on how to deploy these rules.  
   - Stricter rules are not needed unless absolutely necessary. If required, confirm with me first.  

3. Step-by-Step Integration:  
   - Provide actionable guidance for implementing Firestore based on the confirmed data structure.  
   - Include any necessary utility files or helper code snippets.  

4. Testing and Updates:  
   - Suggest how to test the integration thoroughly.  
   - Provide instructions on how to update security rules in the future.  

Please do not execute code directly. Focus on confirming and guiding at each step.
Firebase Console
Firebase Integration Guide.
here
here