Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firestore#delete not working with the emulator after more or less recent change #3084

NeverwinterMoon opened this issue Jan 27, 2021 · 3 comments · Fixed by #3099


Copy link

NeverwinterMoon commented Jan 27, 2021

[REQUIRED] Environment info



[REQUIRED] Test case

Check the steps to reproduce. It does not require anything else. Downgrading firebase-tools to, say, 8.16.2, works with that same code.

[REQUIRED] Steps to reproduce

Have emulators running, then

process.env.FIREBASE_AUTH_EMULATOR_HOST = 'localhost:9099'
process.env.FIRESTORE_EMULATOR_HOST = 'localhost:8080'
process.env.NODE_ENV = 'development'

firebaseTools.firestore.delete(userRef.path, {
    project:   admin.instanceId().app.options.projectId,
    recursive: true,
    yes:       true

[REQUIRED] Expected behavior

Before this commit (9d90a94), which added apiv2 to requireAuth.ts, having process.env.FIREBASE_TOKEN = 'FAKE_TOKEN' was enough to work with the local emulator. After this change, it's not possible.

There was a fix for api.js here ( which uses var getTokenPromise = secureRequest ? api.getAccessToken() : Promise.resolve({ access_token: "owner" });. apiv2 on the other hand has just const token = await this.getAccessToken()

[REQUIRED] Actual behavior

Error is returned: "Failed to fetch page after undefined FirebaseError: HTTP Error: 400, invalid jwt" from apiv2.js

Copy link

@NeverwinterMoon thanks for the detailed bug! What happens if you don't set FIREBASE_TOKEN at all?

Assigning to @bkendall since this looks like an apiv2 regression.

Copy link

Without setting FIREBASE_TOKEN environment variable it will fail even earlier, at requireAuth, with Failed to authenticate as it requires either process.env.FIREBASE_TOKEN or firebase login on the machine where it's running.

I actually found out that setting process.env.FIREBASE_TOKEN to owner (similarly to what api.js does in the aforementioned change) works with the latest firebase-tools. Nonetheless, api1 did set this automatically to owner no matter what value was set to FIREBASE_TOKEN and api2 doesn't...

Overall, I think it might make sense to at least document these things. I love the possibility to use emulators not only for local development (in this case I have firebase login, so no token setting is necessary) but also for the automated tests and setting up some of the things, like using Firebase CLI tools against the emulator, is somewhat troublesome.

Copy link

I was wrong, the above does not help, must have mixed some up. apiv2 just fails after response deletePath:initialDelete:error FirebaseError: HTTP Error: 401, Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential..

Anyway, my idea was to be able to run tests against emulators without the need to having the actual authentication. As far as I read, only the hosting emulator requires the authentication. Furthermore, this did work for me for some time before I've updated firebase-tools.

This was referenced Mar 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging a pull request may close this issue.

3 participants