firebase / firebase/firebase-admin-node

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

Abierto
#2,325 4 comentarios 6 reacciones 0 asignados Ver en GitHub
api: core
Lenguaje dominante
TypeScript
Estrellas
1.7k
Forks
419
Merge medio
3 d 10 h
PR fusionados (30 d)
16

Descripción

### [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)
```

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.