/lovable-integrations

Lovable and Google Cloud Firestore integration: Step-by-Step Guide 2025

Discover how to integrate Lovable with Google Cloud Firestore using our step-by-step guide. Learn best practices for seamless app development and cloud data management.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free No-Code consultation

How to integrate Lovable with Google Cloud Firestore?

 

Adding Firestore Dependencies via Code

 

Since Lovable doesn’t provide terminal access, you need to ensure that Firestore dependencies are listed in your project’s package configuration. Open your project’s package.json file and add the following dependencies in the "dependencies" section. This will instruct Lovable’s build system to install them:


{
  "dependencies": {
    "@google-cloud/firestore": "^6.5.0",
    "typescript": "^4.5.4"
    // ... other dependencies
  }
}

Place the updated package.json file at the root of your Lovable project.

 

Creating the Firestore Initialization File

 

Create a new file in your project to handle Firestore initialization. For example, create a file named firestore.ts in a folder such as src/config (create the folder if it doesn’t exist). This file will initialize the Firestore client using your Google Cloud project credentials.


import { Firestore } from '@google-cloud/firestore';

// Replace 'your-project-id' with your actual Google Cloud Project ID
// Replace 'path/to/your/service-account-file.json' with the path to your service account JSON file
const firestore = new Firestore({
  projectId: 'your-project-id',
  keyFilename: 'path/to/your/service-account-file.json'
});

export default firestore;

Remember to upload your service account JSON file into a secure location within your project (preferably outside of the public directory) and adjust the keyFilename path accordingly.

 

Integrating Firestore into Your Application Code

 

Decide where you need Firestore within your Lovable project. For example, if you have a file handling data operations (e.g. dataService.ts), import the Firestore instance and use it for database operations. Open or create the file dataService.ts in your project’s appropriate directory and add the following code:


import firestore from './config/firestore';

// Example function to add a document to a Firestore collection
export async function addDocument(collectionName: string, data: any) {
  try {
    const docRef = firestore.collection(collectionName).doc();
    await docRef.set(data);
    console.log('Document written with ID: ', docRef.id);
    return docRef.id;
  } catch (error) {
    console.error('Error adding document: ', error);
    throw error;
  }
}

// Example function to read documents from a Firestore collection
export async function getDocuments(collectionName: string) {
  try {
    const snapshot = await firestore.collection(collectionName).get();
    const docs: any[] = [];
    snapshot.forEach(doc => {
      docs.push({ id: doc.id, data: doc.data() });
    });
    return docs;
  } catch (error) {
    console.error('Error getting documents: ', error);
    throw error;
  }
}

Place this file in a logical part of your project (e.g. src/services) so that your other project files can import and use these functions.

 

Using Firestore Functions in Your Application

 

Wherever you need to interact with Firestore (for example in a component or a controller), import the functions created in dataService.ts. For demonstration, if you have a main file (e.g. main.ts), include the following snippet:


import { addDocument, getDocuments } from './services/dataService';

// Example usage: Adding a new document
async function runDemo() {
  try {
    const newDocId = await addDocument('users', { name: 'Alice', age: 30 });
    console.log('New document added with ID:', newDocId);

    // Example usage: Retrieving documents
    const users = await getDocuments('users');
    console.log('Retrieved users:', users);
  } catch (error) {
    console.error('Firestore operation failed:', error);
  }
}

runDemo();

This code demonstrates basic addition and retrieval of documents from a Firestore collection. Insert these import statements and function calls into the relevant part of your Lovable project where Firestore data operations are required.

 

Finalizing Integration

 

Once you have added the dependency information in package.json, created the Firestore initialization file, and integrated the Firestore functions in your project files, your Lovable project is set to leverage Google Cloud Firestore. Save all files and allow Lovable’s build process to pick up these changes. No terminal commands are required; changes in the package.json signal dependency installations automatically within Lovable’s environment.

 

Still stuck?
Copy this prompt into ChatGPT and get a clear, personalized explanation.

This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.

AI AI Prompt

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022