firebase-tools
firebase-tools copied to clipboard
`auth:export` fails after 60 minutes with TypeError: Cannot read properties of undefined (reading 'access_token')
[REQUIRED] Environment info
firebase-tools: 14.4.0
Platform: macOS
[REQUIRED] Test case
firebase auth:export auth.csv --project <project-id> --debug
[REQUIRED] Steps to reproduce
Run firebase auth:export auth.csv --project <project-id> --debug for a large project with > 10M users.
[REQUIRED] Expected behavior
The script should succeed with all the accounts exported.
[REQUIRED] Actual behavior
The command fails after exactly 60 minutes with the following error on the output. There are only about 5M users exported in the CSV.
[2025-05-22T08:46:30.588Z] >>> [apiv2][body] POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/downloadAccount {"targetProjectId":"fitify-app","maxResults":1000,"nextPageToken":"HWgDqeyrQdhp9F18qE2ETlcZij72"}
[2025-05-22T08:46:30.730Z] <<< [apiv2][status] POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/downloadAccount 401
[2025-05-22T08:46:30.730Z] <<< [apiv2][body] POST https://www.googleapis.com/identitytoolkit/v3/relyingparty/downloadAccount [omitted]
[2025-05-22T08:46:30.731Z] Got a 401 Unauthenticated error for a call that required authentication. Refreshing tokens.
[2025-05-22T08:46:30.732Z] No OAuth tokens found
[2025-05-22T08:46:30.732Z] No OAuth tokens found
[2025-05-22T08:46:30.732Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2025-05-22T08:46:30.779Z] Running auto auth
[2025-05-22T08:46:30.785Z] TypeError: Cannot read properties of undefined (reading 'access_token')
at getAccessToken (/Users/fitify/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/apiv2.js:43:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RetryOperation._fn (/Users/fitify/.cache/firebase/tools/lib/node_modules/firebase-tools/lib/apiv2.js:303:40)
Error: An unexpected error has occurred.
This issue does not have all the information required by the template. Looks like you forgot to fill out some sections. Please update the issue with more information.
Hi @MattSkala, sorry to hear that you are running into this. It looks your the OAuth refresh token is expiring in the middle of the command. I will take a look at the auth logic that is misbehving here, but as an immediate workaround, you can use a service account instead (as described in https://stackoverflow.com/questions/59053919/login-to-firebase-using-gcloud-service-account). Service account credentials are long lived, so they will not run into this problem.
@joehan Thanks for your response. However, I already am using the service account defined in GOOGLE_APPLICATION_CREDENTIALS env variable for authentication. Do you have any other ideas for a possible workaround?
Hey @MattSkala, could you try authenticating via firebase login? I tried to reproduce this issue and it seems like this occurs when using GOOGLE_APPLICATION_CREDENTIALS. When trying with credentials from firebase login, the export completes without any issues even after running for ~2 hours.
For context, I can’t replicate the scenario with 10M users, so I created ~20K users and manually modified my local firebase-tools and lowered the batch size to 1 to make the export run longer
https://github.com/firebase/firebase-tools/blob/5409db808d386e8fa26bfb3224b57f2e41e664f4/src/commands/auth-export.ts#L11
After doing the changes and authenticating with GOOGLE_APPLICATION_CREDENTIALS, I’m able to encounter the issue
[2025-06-11T19:13:58.326Z] Running auto auth
[2025-06-11T19:13:58.335Z] TypeError: Cannot read properties of undefined (reading 'access_token')
at getAccessToken (/usr/local/lib/node_modules/firebase-tools/lib/apiv2.js:43:17)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async RetryOperation._fn (/usr/local/lib/node_modules/firebase-tools/lib/apiv2.js:303:40)
Same here. We can't use firebase login because we are running on CI. We use GOOGLE_APPLICATION_CREDENTIALS with the service account. Functions deployment takes time, sometimes more than 1 hour.
We start experiencing this issue after updating from v13 to v14. Please fix it or give an advice how to workaround it. Thanks.