|
| 1 | +--- |
| 2 | +slug: /integrations/firebase |
| 3 | +title: Firebase |
| 4 | +description: Learn how to connect your Dreamflow app with Firebase to enable powerful backend features such as authentication, real-time databases, analytics, and more. |
| 5 | +tags: [Firebase, Integration, Dreamflow, Backend] |
| 6 | +sidebar_position: 1 |
| 7 | +toc_max_heading_level: 4 |
| 8 | +keywords: [Firebase, Integration, Dreamflow, Backend] |
| 9 | +--- |
| 10 | + |
| 11 | +# Firebase |
| 12 | + |
| 13 | +Dreamflow makes it easy to integrate [Firebase](https://firebase.google.com/) into your app with a guided, step-by-step setup. This process connects your project to Firebase, generates all necessary configuration, and even creates ready-to-use client code and database rules with AI. |
| 14 | + |
| 15 | +By integrating Firebase, you gain access to services such as Authentication, Firestore Database, Cloud Storage, Hosting and more, giving your app a secure backend for managing users, data, and serverless logic. |
| 16 | + |
| 17 | +## 1. Connection |
| 18 | + |
| 19 | +The first step is to connect Dreamflow with your Google account so it can create new Firebase projects or link to existing ones. |
| 20 | + |
| 21 | +To connect Dreamflow with Firebase, open the **Firebase** tab in Dreamflow, then click **Connect to Firebase**. When the OAuth window appears, sign in with your Google account, review, and approve the requested permissions. These permissions allow Dreamflow to create Firebase projects, manage configurations, and deploy security rules. |
| 22 | + |
| 23 | +Once complete, Dreamflow will confirm the connection with a **Connected** status. |
| 24 | + |
| 25 | +<div style={{ |
| 26 | + position: 'relative', |
| 27 | + paddingBottom: 'calc(52.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding |
| 28 | + height: 0, |
| 29 | + width: '100%'}}> |
| 30 | + <iframe |
| 31 | + src="https://demo.arcade.software/Iu2hoVYZN1EV5IscOzNy?embed&show_copy_link=true" |
| 32 | + title="" |
| 33 | + style={{ |
| 34 | + position: 'absolute', |
| 35 | + top: 0, |
| 36 | + left: 0, |
| 37 | + width: '100%', |
| 38 | + height: '100%', |
| 39 | + colorScheme: 'light' |
| 40 | + }} |
| 41 | + frameborder="0" |
| 42 | + loading="lazy" |
| 43 | + webkitAllowFullScreen |
| 44 | + mozAllowFullScreen |
| 45 | + allowFullScreen |
| 46 | + allow="clipboard-write"> |
| 47 | + </iframe> |
| 48 | +</div> |
| 49 | +<p></p> |
| 50 | + |
| 51 | + |
| 52 | +## 2. Project Setup |
| 53 | + |
| 54 | +After connecting your Google account, the next step is to set up a Firebase project, which will serve as the backend for your app. You can do this in two ways: |
| 55 | + |
| 56 | +- **Select an existing Firebase project:** Choose from the list of your existing Firebase projects. |
| 57 | + |
| 58 | +  |
| 59 | +- **Create a new Firebase project:** Let Dreamflow automatically create and configure a new Firebase project for you. |
| 60 | + |
| 61 | +  |
| 62 | + |
| 63 | +Once the project is linked, you need to specify the following: |
| 64 | + |
| 65 | +- **Target Platforms:** Choose the platforms you want to support (Web, iOS, Android, macOS, Linux, Windows). Web is always enabled by default, so your app can be previewed inside Dreamflow. Selecting the right platforms ensures Firebase generates configs for each build target. |
| 66 | +- **Bundle ID:** Enter a unique **Bundle ID** (e.g., `com.yourcompany.appname`). This must match the app identifier in your platform-specific builds (iOS bundle ID, Android package name). If you skip this, Firebase cannot configure services for mobile apps. |
| 67 | + |
| 68 | +When these details are set, click **Configure Firebase** to complete the setup. |
| 69 | + |
| 70 | +<div style={{ |
| 71 | + position: 'relative', |
| 72 | + paddingBottom: 'calc(52.67989417989418% + 41px)', // Keeps the aspect ratio and additional padding |
| 73 | + height: 0, |
| 74 | + width: '100%'}}> |
| 75 | + <iframe |
| 76 | + src="https://demo.arcade.software/Ux3hDEIPtZ1qaVHtIKnf?embed&show_copy_link=true" |
| 77 | + title="" |
| 78 | + style={{ |
| 79 | + position: 'absolute', |
| 80 | + top: 0, |
| 81 | + left: 0, |
| 82 | + width: '100%', |
| 83 | + height: '100%', |
| 84 | + colorScheme: 'light' |
| 85 | + }} |
| 86 | + frameborder="0" |
| 87 | + loading="lazy" |
| 88 | + webkitAllowFullScreen |
| 89 | + mozAllowFullScreen |
| 90 | + allowFullScreen |
| 91 | + allow="clipboard-write"> |
| 92 | + </iframe> |
| 93 | +</div> |
| 94 | +<p></p> |
| 95 | + |
| 96 | + |
| 97 | +:::info |
| 98 | + |
| 99 | +Behind the scenes, Dreamflow uses the **FlutterFire CLI** to handle the configuration. This process generates a `firebase_options.dart` file containing project-specific credentials such as API keys, app ID, and messaging sender ID. These credentials ensure your app is properly connected to Firebase services. |
| 100 | + |
| 101 | +::: |
| 102 | + |
| 103 | +:::warning |
| 104 | + |
| 105 | +Once configured, changing the **Bundle ID** later will require reconfiguring Firebase and may break existing builds. Choose carefully before proceeding. |
| 106 | + |
| 107 | +::: |
| 108 | + |
| 109 | +## 3. Generate Client Code |
| 110 | + |
| 111 | +Once your Firebase project is linked and configured, click **Generate with Agent** to automatically add the code needed to access Firebase services. This step automates a complete Firebase integration tailored to your app, wiring up authentication, Firestore, state management, and updating the existing app logic with little to no manual effort. |
| 112 | + |
| 113 | +:::info |
| 114 | + |
| 115 | +- This step is optional, but we strongly recommend doing it. It saves significant development time by scaffolding schemas, services, and security rules automatically to ensure your Firebase integration is both secure and production-ready from the start. |
| 116 | +- The generated code is fully editable and serves as a starting point for customization. |
| 117 | + |
| 118 | +::: |
| 119 | + |
| 120 | + |
| 121 | + |
| 122 | +### Code Generation Breakdown |
| 123 | + |
| 124 | +When you click **Generate with Agent**, Dreamflow performs several background steps, including (but not limited to): |
| 125 | + |
| 126 | +- **Firebase Configuration Files** |
| 127 | + - Creates and updates core Firebase files such as `firebase.json`, `firestore.rules`, `firestore.indexes.json`, and `firebase_options.dart`. |
| 128 | + - These files define how your app connects to Firebase, which services are enabled, and enforce security rules and query indexes. |
| 129 | +- **Firestore Schema & Services** |
| 130 | + - Generates a `firestore_data_schema.dart` file to define collections and documents. |
| 131 | + - Implements a `firebase_service.dart` repository class to handle Firestore operations (CRUD, queries, synchronization). |
| 132 | + - Adds indexes and security rules to enforce per-user access control. |
| 133 | +- **Authentication System** |
| 134 | + - Creates an `auth_service.dart` for sign-in/sign-out logic. |
| 135 | + - Adds an `auth_wrapper.dart` to manage authentication state across the app. |
| 136 | + - Updates `main.dart` to initialize Firebase and route users based on authentication state. |
| 137 | +- **App Screens** |
| 138 | + - Updates app pages to fetch and display live data from Firestore instead of hardcoded values. |
| 139 | + - Adds authentication screens to handle user sign-in and sign-up flows. |
| 140 | +- **Dependencies & Compilation** |
| 141 | + - Updates `pubspec.yaml` with required Firebase dependencies. |
| 142 | + - Resolves version conflicts and ensures successful compilation. |
| 143 | + |
| 144 | + |
| 145 | +:::info[Enable Services in Firebase Console] |
| 146 | + |
| 147 | +After Dreamflow generates code for Firebase services, you must enable those services in the Firebase Console for them to function correctly. For example: |
| 148 | + |
| 149 | +- **Authentication:** Enable required sign-in methods such as Email/Password or Social Sign-in. |
| 150 | +- **Firestore Database:** Activate Firestore in the console to store and retrieve data. |
| 151 | +- **Firebase Storage:** Enable Storage to handle file uploads and downloads. |
| 152 | + |
| 153 | +::: |
| 154 | + |
| 155 | +## 4. Deploy to Firebase |
| 156 | + |
| 157 | +The final step is to deploy the generated schemas, indexes, and rules to Firebase so they become active in your project. For example, in a habit tracker app, Dreamflow deploys rules that allow only the authenticated user to modify their habits collection. |
| 158 | + |
| 159 | +To deploy to Firebase: |
| 160 | + |
| 161 | +1. In the **Actions** panel, go to **Deploy to Firebase**. Under **Deployment Target**, select the Firebase service you want to deploy to (default is *Firestore*). |
| 162 | +2. Click **Deploy Changes**. |
| 163 | + |
| 164 | +:::info |
| 165 | + |
| 166 | +- Until you deploy, rules and schemas only exist in Dreamflow and are not sent to Firebase. |
| 167 | +- Dreamflow uses the Firebase CLI to push security rules, indexes, and any additional configurations (e.g., Auth, Storage) to Firebase. |
| 168 | + |
| 169 | +::: |
| 170 | + |
| 171 | +:::warning |
| 172 | + |
| 173 | +This step is critical for security, as without rules, your Firestore may be open to anyone. |
| 174 | + |
| 175 | +:::: |
| 176 | + |
| 177 | + |
| 178 | + |
0 commit comments