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:
- 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).
- 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.
- 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.
- IAM Permissions: Confirmed that the service account has the “Firebase Authentication Admin” role, which should grant necessary permissions.
- Firebase Provider: Verified in the Firebase Console that “Phone number” is an enabled sign-in provider.
- Explicit Project ID: Modified the admin.initializeApp call to explicitly include the projectId.
- 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.