Skip to content

Calling Firebase function from Node.js results in FirebaseError: internal #7636

@matallui

Description

@matallui

Operating System

macOS

Browser Version

Arc

Firebase SDK Version

10.4.0

Firebase SDK Product:

Functions

Describe your project's tooling

Next.js 13 (app router) with RSC.
The goal is to be able to call a firebase functions from both client and server components.

Describe the problem

I'm trying to setup a Next.js 13 (app router) application in a way that I could call a callable Firebase function from both client and server components.

When called from a client component (aka browser) everything seems to work fine.
However, when called from a server component (aka Node.js) I get an internal error with the code functions/internal.

Steps and code to reproduce issue

In order to reproduce this issue, all you have to do is run the following code in Node.js:

import { getApp, getApps, initializeApp } from "firebase/app";
import {
  connectFunctionsEmulator,
  getFunctions,
  httpsCallable,
} from "firebase/functions";

const firebaseConfig = {
  apiKey: process.env.NEXT_PUBLIC_FIREBASE_API_KEY,
  authDomain: process.env.NEXT_PUBLIC_FIREBASE_AUTH_DOMAIN,
  projectId: process.env.NEXT_PUBLIC_FIREBASE_PROJECT_ID,
};

const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();

const functions = getFunctions(app);
connectFunctionsEmulator(functions, "localhost", 5001);

const helloWorld = httpsCallable(functions, "helloWorld", {
  timeout: 1000,
});

console.log("Calling helloWorld function...");

const res = await helloWorld();
console.log(res.data);

You'd have to replace the environment variables with your own, as well as make sure the helloWorld() function is defined as a callable Firebase function:

import * as logger from "firebase-functions/logger";
import { onCall } from "firebase-functions/v2/https";

export const helloWorld = onCall((_req) => {
  logger.info("Hello logs!", { structuredData: true });
  return {
    message: "Hello from Firebase!",
  };
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions