diff --git a/docs/ff-concepts/adding-customization/cloud-functions.md b/docs/ff-concepts/adding-customization/cloud-functions.md index a9faeda6..12b5c6a4 100644 --- a/docs/ff-concepts/adding-customization/cloud-functions.md +++ b/docs/ff-concepts/adding-customization/cloud-functions.md @@ -9,16 +9,22 @@ keywords: [FlutterFlow, Cloud Functions, Serverless, Integration] # Cloud Functions -[**Cloud Functions**](https://firebase.google.com/docs/functions) allows you to run backend code in response to events triggered by Firebase features and HTTPS requests. For example, you want to automatically send a welcome email to users when they sign up for your app. You can do this using a Cloud Function that triggers on Firebase Authentication's user creation event. +Cloud Functions let you run backend code in response to events and API requests without managing your own servers. They are commonly used for tasks such as processing data, calling external APIs, sending notifications, running AI workflows, or securely handling secrets and business logic. -We allow you to write and deploy Firebase Cloud Functions directly within the platform. With an integrated code editor, writing JavaScript cloud functions is quick and user-friendly. Each function has customizable boilerplate settings, including pre-configured essentials like memory, region, and timeout. +FlutterFlow supports both Firebase Cloud Functions and Supabase Edge Functions, allowing you to build scalable backend workflows. + +## Firebase Cloud Functions + +[**Firebase Cloud Functions**](https://firebase.google.com/docs/functions) allow you to run server-side Node.js code triggered by Firebase services and HTTPS requests. For example, you can automatically send emails, process uploads, generate AI content, or react to database changes. + +FlutterFlow includes built-in support for creating, editing, deploying, and triggering Firebase Cloud Functions directly from the platform. :::note Read up on some interesting use cases of [**Cloud Functions**](https://firebase.google.com/docs/functions/use-cases). ::: -## Adding Cloud Functions +### Adding Cloud Functions Let's see how to add a *Cloud Function* by building an example that generates logos based on user prompts. Here's how it looks: @@ -31,13 +37,6 @@ The Cloud Function takes input from a TextField widget and initiates an API call Here are the step-by-step instructions to build such an example: -1. [Add page state variables](#1-add-page-state-variables) -2. [Build a page](#2-build-a-page) -3. [Create and deploy Cloud Function](#3-create-and-deploy-cloud-function) -4. [Optional: Add package](#4-optional-add-package) -5. [Trigger Cloud Function](#5-trigger-cloud-function) -6. [Optional: Use Cloud Function result](#6-optional-use-cloud-function-result) - :::info[Before you Begin] * Make sure the project is on Blaze plan on Firebase. @@ -45,7 +44,7 @@ Here are the step-by-step instructions to build such an example: [**Firebase Setup**](../../ff-integrations/firebase/connect-to-firebase-setup.md). ::: -### 1. Add page state variables +#### 1. Add page state variables For this example, you'll need to set up two [Page State variables](../../resources/ui/pages/page-lifecycle.md#creating-a-page-state): @@ -57,7 +56,7 @@ loading indicator during the logo creation process. Its value is set to *True* b
 -### 2. Build a page +#### 2. Build a page Let's add a page that allows users to enter the prompt. To speed up, you can add a page from the template or use [AI Page Gen](../../resources/ui/pages/intro-pages.md#create-an-ai-generated-page). Here is the page added using AI Page Gen, and after some modification, it looks the below: @@ -70,7 +69,7 @@ Few things to note here: * We use the [**ConditionalBuilder**](../layout/responsive-widgets/conditional-builder-widget.md) widget to show/hide the loading indicator based on the *generatingImage* variable. **Tip**: The Else branch of this widget is nothing but a ProgressBar inside the Container with a [rotating loop animation](../animations/widget_animations.md). * The Image widget uses the *logoImage* variable to display the logo. -### 3. Create and deploy Cloud Function +#### 3. Create and deploy Cloud Function To create and deploy a *Cloud Function* : @@ -80,7 +79,7 @@ To create and deploy a *Cloud Function* : 2. Click **+ Add**. This will add the default `newCloudFunction`. 3. Set the **Cloud Function Name**. -#### Boilerplate Settings +##### Boilerplate Settings On the right side, you can configure the following Boilerplate Settings: 1. **Memory Allocation**: You can specify the amount of memory your function should have when @@ -92,7 +91,7 @@ On the right side, you can configure the following Boilerplate Settings:  -#### Configuring Input & Output +##### Configuring Input & Output Your cloud function might need some data to process and return the result. You can do so by configuring the input and output. @@ -131,7 +130,7 @@ For a list, the function should return: }); ``` -#### To deploy +##### To deploy 1. Click the `[>]` icon to view the boilerplate code; a popup will open with the updated code, and then click **`> Copy to Editor`**. **Tip**: To see if you are able to deploy the cloud function (before adding your own code), proceed directly with steps 8 and 9. @@ -220,7 +219,7 @@ com/embed/1dc13a747b6b4f6d9c9f6d3e1721e488?sid=a756ed68-f20a-4723-8a89-bc1462ede -### 4. Optional: Add package +#### 4. Optional: Add package Your cloud function may require third-party packages to work. You can include any npm package (dependency) by listing it in the `package.json` file. This file not only manages the npm package dependencies for your functions but also holds project metadata, sets up scripts for tasks such as deployment and outlines the compatible Node.js versions. @@ -228,7 +227,7 @@ To add a dependency, open the `package.json` file and specify your package in th  -### 5. Trigger Cloud Function +#### 5. Trigger Cloud Function The newly created *Cloud Function* will be available as an action when you are adding one. For this example, on click of a button, we'll first set the *generatingImage*to *True* and then trigger the **Cloud Function Action**. @@ -236,7 +235,7 @@ The newly created *Cloud Function* will be available as an action when you are a com/embed/5c712863f95c4fcabd5c3851a3cbe56b?sid=a7ac875f-11b5-4b5a-b3e2-8ae03ce49571" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen> -### 6. Optional: Use Cloud Function result +#### 6. Optional: Use Cloud Function result To use the *Could Function* result, ensure you provide the *Action Output Variable Name* while adding the action, and then you can access it via the **Set from Variable menu > Action Outputs > [Action Output Variable Name]**. @@ -245,7 +244,7 @@ For this example, we'll use the result (i.e., generated logo image URL) and set -## Testing Cloud Functions in Google Cloud console +### Testing Cloud Functions in Google Cloud console The Google Cloud console has built-in functionality to allow you to trigger a Cloud Function for testing. This means that after deploying Cloud Functions, you can test them without writing to Firestore (either from FlutterFlow or otherwise). @@ -285,7 +284,7 @@ The `fields` in the example above are for FlutterFlow's built-in `sendUserPushNo The Cloud Function will now run and gather the relevant entries from Google Cloud Logging. -## FAQs +### FAQs