• Blog
  • Documentation
  • Courses
  • Changelog
  • AI Starters
  • UI Kit
  • FAQ
  • Supamode
    New
  • Pricing

Launch your next SaaS in record time with Makerkit, a React SaaS Boilerplate for Next.js and Supabase.

Makerkit is a product of Makerkit Pte Ltd (registered in the Republic of Singapore)Company Registration No: 202407149CFor support or inquiries, please contact us

About
  • FAQ
  • Contact
  • Verify your Discord
  • Consultation
  • Open Source
  • Become an Affiliate
Product
  • Documentation
  • Blog
  • Changelog
  • UI Blocks
  • Figma UI Kit
  • AI SaaS Starters
License
  • Activate License
  • Upgrade License
  • Invite Member
Legal
  • Terms of License
  • Auth Overview
  • Global Configuration
    • Setting up your Firebase Project
    • Setting up Firebase Functions
  • Writing data to Firestore
  • Commands
  • Introduction
  • Production Checklist
  • Introduction
  • Overview
  • Stripe Configuration
  • Running Tests
  • Introduction
  • Setting up Firebase Auth
  • Fetching data from Firestore
  • Technical Details
  • Extending Organizations
  • Stripe Webhooks
  • CI Tests
  • Initial Setup
  • React Hooks
  • Auth Flow
  • API requests
  • Code Style
  • Clone the repository
  • Security Rules
  • User Permissions
  • Limitations
  • Project Structure
  • Third-Party Providers
  • Reading data from Storage
  • Running the application
  • Subscription Permissions
  • One-Time Payments
  • Running the App
  • Email Link Authentication
  • Uploading data to Storage
  • Security Rules
  • Migrate to Lemon Squeezy
  • Project Configuration
  • Multi-Factor Authentication
  • Writing your own Fetch
  • Translations and Locales
  • Coding Conventions
  • Environment Variables
  • Architecture and Folder Structure
    • Structure your Application
    • Data Model
  • Requiring Email verification
  • Sending Emails
  • Tailwind CSS and Styling
  • Validating API payload with Zod
  • Authentication
  • Onboarding Flow
  • Logging
  • Development: adding custom features
  • Prevent abuse with AppCheck
  • Enable CORS
  • Encrypting Secrets
  • User Roles
  • Firestore: Data Fetching
  • Custom React Hooks
  • Custom React Hooks
  • Firestore: Data Writing
  • Troubleshooting
  • Forms
  • Application Pages
  • API Routes
  • API Routes Validation
  • Translations
  • Adding pages to the Marketing Site
  • Deploying to Production
  • Updating to the latest version
This kit is no longer maintained.

Setting up Firebase Functions for your MakerKit application

Learn how to set up Firebase Functions in your Makerkit SaaS project

Setting Firebase Functions is optional. You only need to set up Firebase Functions if you need certain features, such as Firestore Triggers, Storage Triggers, Authentication Blocking Functions, etc.

While you may want to use Remix's own API functions for your application's API, there are many scenarios where you may be required to use Firebase Functions, for example:

  1. You want to implement Authentication Blocking Functions
  2. You need to use Firebase Storage Triggers
  3. You need to use Firebase Firestore Triggers

Therefore, it's essential to know how to set up Firebase Functions in a Remix environment, such as the Makerkit SaaS template.

Initializing Firebase Functions

Assuming you have a working Makerkit project installed, let's type the following command in your terminal:

text
firebase init functions

When prompted about creating a new project, choose not to create a default project, as you may have already done it.

After completing the CLI prompts, you should have a few more files in your project:

text
✔ Wrote functions/package.json
✔ Wrote functions/tsconfig.json
✔ Wrote functions/src/index.ts
✔ Wrote functions/.gitignore

Adjust or delete the eslint configuration file

You may need to delete (or adjust) the eslint file generated by the CLI, as it may conflict with the one in the root of your project. We recommend using the one in the root of your project shipped with Makerkit.

If you leave it as is, you may see linting errors in your functions code, that can also prevent you from deploying your functions.

Firebase Functions setup

I usually proceed to copy some of the scripts to the root package.json, such as the below:

text
"build:functions": "tsc -P functions/tsconfig.json",
"build:functions:watch": "tsc -P functions/tsconfig.json --watch",
"deploy:functions": "firebase deploy --only functions"
  1. build:functions builds the functions bundle and then exits
  2. build:functions:watch builds the functions in development mode, so it will re-bundle your code on changes
  3. deploy:functions deploys your Functions to the Firebase cloud

Writing your First Function

Let's write our first, very simple Firebase Function:

tsx
import { https } from 'firebase-functions';
export const helloWorld = https.onRequest((req, res) => {
res.send({ Hello: `World` })
});

Running the Firebase Functions emulators

When using Makerkit, simply run the emulators:

text
npm run firebase:emulators:start

If working correctly you'll see the following output:

text
✔ functions: Loaded functions definitions from source: helloWorld.

🎉 And now you can finally use the full power of Firebase's Functions!

Ignore the Firebase Functions folder when deploying to Vercel

Since Firebase Functions are to be deployed to Firebase, you can ignore the functions folder when deploying to Vercel.

To do so, create a file named .vercelignore in the root of your project and add the following line:

text
functions
On this page
  1. Initializing Firebase Functions
    1. Firebase Functions setup
    2. Writing your First Function
    3. Running the Firebase Functions emulators
    4. Ignore the Firebase Functions folder when deploying to Vercel