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

Open
#2,925 6 comments 1 reaction 1 assignee View on GitHub

@lahirumaramba is already working on this.

Since Nov 4, 2025.

Assessment

This issue has not been assessed yet.

Description

api: core
[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
    with the firebase tag.
  • For general Firebase discussion, use the 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.
[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

Steps to reproduce:

Running Firebase Functions emulator on local environment

import { initializeApp } from "firebase-admin/app"

initializeApp()
Relevant Code:
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

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.

Dominant language
TypeScript
Stars
1.7k
Forks
419
Avg merge
3d 10h
Merged PRs (30d)
16

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebase-admin-node

All issues in firebase/firebase-admin-node

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.