Working with Firestore Database

Adding user Data to Firestore Database.

Firebase integrations are for advanced use cases.

Databutton provides native authentication and database capabilities that are automatically included in all new Databutton apps. No additional setup required – simply start building your app and the infrastructure is ready. Native Authentication and Database

Prerequisites

Before you begin, ensure the following are ready

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

    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 Firebase Integration Guide.

Firestore Database Integration Steps

You can watch this video here 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 :

Alternatively, prompt the Agent for Data Structure Suggestions;


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.

Agent Output Example:

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

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:

Last updated

Was this helpful?