-
Notifications
You must be signed in to change notification settings - Fork 2
Firebase functions
In this section, we'll explore how to use Firebase Functions. They're a crucial part of our system. Let's dive in! π
To ensure your Firebase Functions work correctly both locally and when deployed, follow these steps to set up your environment variables:
-
Locate the
.env.template
File - Navigate to thefunctions
folder and find the.env.template
file. This file contains the necessary environment variable keys for your project. -
Create a
.env
File - Copy the.env.template
file and rename the copy to.env
. This file will be used to store your actual environment variable values. -
Replace Values - Open the
.env
file and replace the placeholder values with your actual environment variable values. This step is crucial for the proper functioning of your Firebase Functions both locally and during deployment.
By following these steps, you ensure that your Firebase Functions have the necessary environment variables to operate correctly in any environment. π
To run Firebase Functions locally, follow these steps:
- Install the Firebase CLI - Essential for both local development and deployment. Learn more here π οΈ
- Login to Firebase CLI - Necessary only if you plan to deploy your functions. π
- Select the Project - Required if you're deploying the functions. π
-
Confirmation - To confirm the Firebase CLI is correctly installed, open your terminal and run:
firebase --version
β
To get the Firebase Functions Emulator up and running, follow these steps:
- Install Emulators - If not already done, you may need to install the necessary emulators. Learn more here π¦
-
Initialize Emulators - Run
firebase init emulators
to set up the emulators in your project. This step helps configure the emulators according to your project's needs. π οΈ -
Start the Emulator - From the root of your repository, run
firebase emulators:start --only functions
to start the emulator. π₯οΈ
That's it! You're all set. All details related to the status and logs of your Firebase Functions will be available in the console once the functions start working. Keep an eye on the console for real-time updates and debugging information. π
Working with the Firebase emulator and React Native can be challenging due to the servers running on different systems. The Firebase Functions run on your local machine, while the emulator or testing device runs on your phone or inside the machine. This setup leads to different localhost
environments, making it impossible to access the functions directly from your phone.
To address the challenge of different localhost environments between the Firebase emulator (running on your local machine) and your React Native app (running on a phone or emulator), we've implemented a solution using HTTP callable functions.
-
Create HTTP Callable Functions: These functions can be invoked via HTTP requests, making them accessible regardless of the
localhost
issue. - Testing with Postman or Thunder Client: Before integrating with your React Native app, test the HTTP callable functions using tools like Postman or Thunder Client, both available as VS Code extensions. This ensures the functions behave as expected.
- Why Deployment is Necessary: For your React Native app to access the Firebase Functions, you must deploy them. This is because the app can only interact with deployed functions, bypassing the localhost discrepancy issue.
By following these steps, you can effectively bridge the gap between your Firebase Functions and React Native app, ensuring a smooth development and testing process.