firebase / firebase/firebase-admin-node

auth.createCustomToken: Failed to determine service account. Make sure to initialize the SDK with a service account

Đang mở
#2,925 6 bình luận 1 reaction 1 người được giao Được @lahirumaramba nhận Xem trên GitHub
api: core
Ngôn ngữ chính
TypeScript
Star
1.7k
Fork
419
Merge trung bình
3 ngày 10 giờ
Pull request đã merge (30 ngày)
16

Mô tả

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

* For issues related to __the code in this repository__ file a Github issue.
* If the issue pertains to Cloud Firestore, read the instructions in the "Firestore issue"
template.
* For general technical questions, post a question on [StackOverflow](http://stackoverflow.com/)
with the firebase tag.
* For general Firebase discussion, use the [firebase-talk](https://groups.google.com/forum/#!forum/firebase-talk)
google group.
* For help troubleshooting your application that does not fall under one
of the above categories, reach out to the personalized
[Firebase support channel](https://firebase.google.com/support/).

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

* Operating System version: Windows 11 24H2
* Firebase SDK version: 13.4.0
* Firebase Product: Firestore
* Node.js version: 21.6.1
* NPM version: 10.2.4

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

Basically duplicates [2800](https://github.com/firebase/firebase-admin-node/issues/2800)

#### Steps to reproduce:

Running Firebase Functions emulator on local environment
```typescript
import { initializeApp } from "firebase-admin/app"

initializeApp()
```

#### Relevant Code:

```typescript
const token = await auth.createCustomToken(uid, customClaims)
```

This throws

>Failed to determine service account. Make sure to initialize the SDK with a service account credential. Alternatively specify a service account with iam.serviceAccounts.signBlob permission. Original error: Error: Error while making request: getaddrinfo ENOTFOUND metadata.

And I have to do
```typescript
export const json_path = 'LOCAL_PATH'

getApps().length === 0
? initializeApp({
credential: credential.cert(json_path!),
})
: getApp()
```
Which also does not work with ADC file, only with json downloaded from project settings in Firebase dashboard. If I put ADC file path in the snippet above, it complains about project_id field missing. It definitely worked with simply initializeApp() before upgrading to v13.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.