firebase / firebase/firebase-admin-node

Top-level service accessors are broken (TypeError: this.ensureApp(...).auth is not a function)

Aperta
#2,325 4 commenti 6 reazioni 0 assegnatari Vedi su GitHub
api: core
Lingua principale
TypeScript
Stelle
1.7k
Fork
419
Merge medio
3g 10h
PR unite (30g)
16

Descrizione

### [READ] Step 1: Are you in the right place?

This is a bug report.

### [REQUIRED] Step 2: Describe your environment

* Operating System version: macOS Sonoma
* Firebase SDK version: 11.11.0
* Firebase Product: any
* Node.js version: 18.18.0

### [REQUIRED] Step 3: Describe the problem

The top-level service accessors (`auth()`, `firestore()`) provided by the `firebase-admin` don't work when provided an App object. However, the per-product accessors (`getAuth()`, `getFirestore()`) work fine.

Doesn't work:

```ts
import { auth, firestore } from "firebase-admin"
import { initializeApp } from "firebase-admin/app"

const firebase = initializeApp()
const authx = auth(firebase) // this fails
const firestorex = firestore(firebase) // also fails

// These do not fail when passed no args - they properly get the default app.
```

Full error when using accessors with an App instance looks like this:

```
/path/to/node_modules/firebase-admin/lib/app/firebase-namespace.js:136
return this.ensureApp(app).firestore();
^
TypeError: this.ensureApp(...).firestore is not a function
at fn (/path/to/scripts/node_modules/firebase-admin/lib/app/firebase-namespace.js:136:40)
at (/path/to/scripts/src/bootstrap_emulator.ts:8:20)
at Object. (path/to/scripts/src/bootstrap_emulator.ts:19:6)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.S (/path/to/scripts/node_modules/tsx/dist/cjs/index.cjs:1:1250)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at ModuleWrap. (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.18.0
```

However, these do work using per-product accessors:

```ts
import { initializeApp } from "firebase-admin/app"
import { getAuth } from "firebase-admin/auth"
import { getFirestore } from "firebase-admin/firestore"

const firebase = initializeApp()
const authx = getAuth(firebase)
const firestorex = getFirestore(firebase)
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.