Open CodingDoug opened 1 year ago
I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Having the same exact issue
@CodingDoug thanks for providing workaround. The code you provided seems to be namespace API (like in the docs). Judging by client library transitioning to modular api, the same accessors are used there. Supposing what we see is a half-done migration without the proper update of docs.
` require("dotenv").config(); const admin = require("firebase-admin"); const { initializeApp } = require("firebase/app"); const { getAuth } = require("firebase/auth") const { onRequest } = require("firebase-functions/v2/https"); const { onObjectFinalized, onObjectMetadataUpdated } = require("firebase-functions/v2/storage"); const { getStorage, getMetadata, getDownloadURL, listAll, ref, updateMetadata, uploadBytes, uploadString, uploadBytesResumable } = require("firebase/storage");
let firebaseConfig = { apiKey: process.env.API_KEY, authDomain: process.env.AUTH_DOMAIN, projectId: process.env.PROJECT_ID, storageBucket: process.env.STORAGE_BUCKET, messagingSenderId: process.env.MESSAGING_SENDER_ID, appId: process.env.APP_ID, measurementId: process.env.MEASUREMENT_ID, auth: true, credential: admin.credential.applicationDefault(), };
initializeApp(firebaseConfig); // Initialize the Firebase app
let app = initializeApp(firebaseConfig); let storage = getStorage(app); let auth = getAuth(app);
module.exports = { app, auth, admin, ref, storage, listAll, getMetadata, getDownloadURL, uploadBytes, uploadString, updateMetadata, onRequest, onObjectFinalized, onObjectMetadataUpdated, uploadBytesResumable }; ` Error thrown:
TypeError: this.ensureApp(...).auth is not a function at FirebaseNamespace.fn (C:\Users\...\firebase-admin\lib\app\firebase-namespace.js:92:40) at new Auth (C:\Users\...\functions\controllers\AuthCT.js:15:28) at new Functions (C:\Users\...\functions\functions.js:16:24) at Object.<anonymous> (C:\Users\...\functions\index.js:2:27) at Module._compile (node:internal/modules/cjs/loader:1376:14) at Module._extensions..js (node:internal/modules/cjs/loader:1435:10) at Module.load (node:internal/modules/cjs/loader:1207:32) at Module._load (node:internal/modules/cjs/loader:1023:12) at Module.require (node:internal/modules/cjs/loader:1235:19) at require (node:internal/modules/helpers:176:18)
[READ] Step 1: Are you in the right place?
This is a bug report.
[REQUIRED] Step 2: Describe your environment
[REQUIRED] Step 3: Describe the problem
The top-level service accessors (
auth()
,firestore()
) provided by thefirebase-admin
don't work when provided an App object. However, the per-product accessors (getAuth()
,getFirestore()
) work fine.Doesn't work:
Full error when using accessors with an App instance looks like this:
However, these do work using per-product accessors: