Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Node.js Cloud Run service gets TypeError: admin.auth(...).signInWithPhoneNumber is not a function d

I am deploying a Node.js/Express backend application on Google Cloud Run. This service uses the Firebase Admin SDK (firebase-admin) to initiate phone number verification server-side within a POST endpoint (/signup). When attempting to call admin.auth().signInWithPhoneNumber(), I consistently encounter a TypeError: admin.auth(...).signInWithPhoneNumber is not a function.

Setup:

  • Backend: Node.js with Express and Firebase Admin SDK.
  • Deployment: Google Cloud Run (europe-central2 region).
  • Firebase Project: Linked to the Google Cloud Project (adykboatsearch). Phone Authentication is enabled as a sign-in provider.
  • Admin SDK Initialization: admin.initializeApp({ credential: admin.credential.applicationDefault(), projectId: 'adykboatsearch' }); is used in my main index.js file.
  • Service Account: The Cloud Run service runs with a dedicated service account (adyk-signup-function@adykboatsearch.iam.gserviceaccount.com) which has the "Firebase Authentication Admin" IAM role (among others).

Error:

The specific error received in the Cloud Run logs is:

Error initiating phone verification: TypeError: admin.auth(...).signInWithPhoneNumber is not a function
    at signUpUser (/app/app/signup.js:94:49) // Line and column number from my latest logs

Debugging Steps Taken:

I have performed extensive troubleshooting to try and resolve this, ruling out common issues:

  1. Code Structure: Confirmed that the Firebase Admin SDK is initialized in the main index.js and the admin object is passed explicitly to the module (signup.js) containing the route handler (signUpUser).
  2. Redundant Require: Verified that there is no top-level const admin = require('firebase-admin'); in the signup.js file; it only uses the admin object passed to its exported function.
  3. Docker Image Content: Ran the deployed Docker image locally and confirmed by inspecting the signup.js file inside the container that the corrected code (without the top-level require) is definitely present in the image.
  4. IAM Permissions: Confirmed that the service account has the "Firebase Authentication Admin" role, which should grant necessary permissions.
  5. Firebase Provider: Verified in the Firebase Console that "Phone number" is an enabled sign-in provider.
  6. Explicit Project ID: Modified the admin.initializeApp call to explicitly include the projectId.
  7. Detailed Logging: Added logging in the signUpUser function just before the admin.auth().signInWithPhoneNumber() call to inspect the admin object and the object returned by admin.auth().

Critical Findings from Logs:

The most surprising result came from the detailed logging (Step 7). The logs show:

admin object: object
authInstance object type: object
Methods available on authInstance:
--- End of authInstance methods ---

This indicates that admin is a valid object, and admin.auth() returns an object (authInstance), but this authInstance object contains no callable methods, including signInWithPhoneNumber.

Expected Behavior:

I expect that after calling admin.auth(), the returned object (authInstance) should be a Firebase Auth instance with methods like signInWithPhoneNumber, createUser, getUser, etc., available for server-side use.

Request for Help:

I am seeking assistance to understand why the object returned by admin.auth() in my Cloud Run environment appears to be empty of methods, leading to this TypeError. Given that the code seems correct, IAM roles are set, and the Firebase provider is enabled, is there a known compatibility issue, a specific configuration required for server-side phone auth initiation in Cloud Run with the Admin SDK, or a potential platform-level problem?

Any insights or suggestions on how to further diagnose or resolve this would be greatly appreciated.

0 1 167
1 REPLY 1

Hi @famous_adequate,

Welcome to the Google Cloud Community!

Thanks for sharing your stack info and the highly detailed debugging steps you did. It really helps that you also included the logs and error messages.

According to the Firebase Authentication API reference for JavaScript, the method signInWithPhoneNumber() does not work in a Node.js environment or with Auth instances created with a FirebaseServerApp. If it’s more feasible, consider implementing other Firebase Authentication methods for your use case or deploy in a different environment.

For now, I recommend creating a Firebase feature request to help with visibility within our engineering team. Do note that there isn’t a specific timeframe for issue resolution. Instead, we wait for a feature to have a handful of stars and, hopefully, comments from several users about how the feature would be useful. You may also open a new issue on the Firebase Admin Node.js SDK GitHub with the details of your use case.

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.