In this section, you’ll learn how to set up Firebase Cloud Functions for an existing Firebase project. We’ll cover creating functions, configuring TypeScript, enabling Secret Manager, and deploying your code.
While you may want to use Next.js's own API functions for your application's API, there are many scenarios where you may be required to use Firebase Functions, for example:
- You want to implement Authentication Blocking Functions (beforeCreate, beforeSignIn)
- You need to use Firebase Storage Triggers
- You need to use Firebase Firestore Triggers (onUserCreate, scheduled events ..) Therefore, it's essential to know how to set up Firebase Functions in a Next.js environment
Open Your Firebase Project
- Go to https://console.firebase.google.com.
- Select the project where you want to enable Cloud Functions.
(Add screenshot: Firebase console project homepage)
Navigate to Functions
- In the left-hand menu, click Create → Functions.
- Note: Functions require a Pay-As-You-Go billing plan. Upgrade if necessary.
- Click Start to initialize Cloud Functions in your project.
(Add screenshot: Firebase Functions overview with Start button)
Update TypeScript Config (Important!)
⚠️ Before deploying your functions, edit the TypeScript configuration to avoid type-checking errors.
- Open
/functions/tsconfig.json. - Under
compilerOptions, add:
"skipLibCheck": true
This tells TypeScript to ignore type checks in node modules, which prevents common deployment errors.
Install Firebase CLI and Initialize Functions
Install Firebase CLI globally:
npm install -g firebase-tools
Initialize Firebase in your project:
firebase init
- When prompted, select Functions (press Spacebar) and then Enter.
- Always choose Use an existing project — we already created it.
- Follow the prompts to complete initialization.
firebase deploy
Note:
you may be asked: How many days do you want to keep container images before they're deleted? keep default value.
you may need to deploy multiple times with different errors (retry if errors of type, cannot find backend specs, timeout, cannot set IAM etc)
Enable Secret manager
You may need to enable secret manager API (We will need this later).
- Go to https://console.cloud.google.com
- Search for Secret Manager API
- Enable it
Ignore functions folder | Vercel
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:
functions