Firebase Integration
In this tutorial, you will learn how to build a real-time event scheduler by integrating DHTMLX Scheduler with Firebase Firestore. This integration provides seamless synchronization of event data between the Scheduler UI and the Firestore database: all updates happen live, across all the connected clients.
You can check the corresponding example on GitHub: DHTMLX Scheduler with Firebase Firestore Demo.
Step 1: Project setup
Let's start by creating a new project directory and initializing a fresh frontend project using Vite:
mkdir scheduler-firebase-demo
cd scheduler-firebase-demo
npm create vite@latest . -- --template vanilla
After Vite has set up the project, clear the src folder to start fresh:
rm -rf src/*
Now, install the necessary dependencies:
npm i dhtmlx-scheduler firebase
Step 2: Create and configure Firebase project
First, create a Firebase project by implementing the following steps:
- go to the Firebase Console
- click Create a project
- enter the project name (e.g.,
scheduler-firebase-demo) and follow the setup prompts
Then set up Firestore by completing the steps below:
- navigate to Firestore Database in your Firebase project dashboard
- click Create database
- select your preferred location
- start in the test mode for ease during the development (remember to configure the security rules before production)
- click Create
After that, register your web app in the following way:
- select Project Overview in the Firebase Console sidebar
- click the web app icon
</>to register a new web app - provide the app nickname (e.g.,
scheduler-firebase-demo) - enable Firebase Hosting
- click Register app
- copy the generated Firebase configuration (you'll use it in your project)
Finally, configure Firebase in your project as described below:
- create a new file
src/firebase.jsand paste your Firebase config, initializing Firebase and Firestore:
[path src/firebase.js](path src/firebase.js)
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "scheduler-firebase-demo.firebaseapp.com",
projectId: "scheduler-firebase-demo",
storageBucket: "scheduler-firebase-demo.appspot.com",
messagingSenderId: "YOUR_SENDER_ID",
appId: "YOUR_APP_ID",
measurementId: "YOUR_MEASUREMENT_ID"
};
const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
export { db };
Replace all the placeholder values (such as YOUR_API_KEY, etc.) with your actual Firebase project credentials.
- install the Firebase CLI globally (for deployment and local emulation) as follows:
npm i -g firebase-tools