fix: initialize auth in requirePermissions before projectId check - #10880
Open
joehan wants to merge 2 commits into
Open
fix: initialize auth in requirePermissions before projectId check#10880joehan wants to merge 2 commits into
joehan wants to merge 2 commits into
Conversation
### Description Fixes an issue where running commands with Application Default Credentials (ADC) without a selected/configured project causes a confusing `Unable to refresh auth: not yet authenticated` error. When a command that performs client-side IAM checks via `requirePermissions` is run without an active project, `requirePermissions` returned early before calling `requireAuth`. This left the local auth state (e.g. `lastOptions` and `accessToken`) uninitialized. When the command's action then proceeded to make API calls (which fallback to the active auth token), the auth client encountered an uninitialized auth state, resulting in a rejected promise with the `Unable to refresh auth` message. This PR fixes it by calling `requireAuth(options)` at the beginning of `requirePermissions`, ensuring that the auth client and local tokens are always initialized before any early return. Fixes #10879 ### Scenarios Tested 1. Tested running `firestore:locations` under ADC without an active project (expected behavior: proper GCP API/project error instead of auth failure). 2. Tested running `firestore:locations` under ADC with a valid project (expected behavior: lists locations successfully). 3. Ran full Mocha test suite (`npm run mocha:fast`) to ensure no regressions in auth hooks. ### Sample Commands - Running without a project (before fix vs after fix): `firebase firestore:locations --debug` - **Before Fix:** ``` Error: Unable to refresh auth: not yet authenticated. ``` - **After Fix:** ``` Error: Request to https://firestore.googleapis.com/v1/projects/null/locations had HTTP Error: 403, Permission denied on resource project null. ``` - Running with a project under ADC: `firebase firestore:locations --project adam-test-c4a4d --debug` - **Before / After Fix:** Lists locations successfully.
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies src/requirePermissions.ts to call requireAuth(options) at the very beginning of the requirePermissions function, before retrieving and checking the project ID. There are no review comments, and I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes an issue where running commands with Application Default Credentials (ADC) without a selected/configured project causes a confusing
Unable to refresh auth: not yet authenticatederror.When a command that performs client-side IAM checks via
requirePermissionsis run without an active project,requirePermissionsreturned early before callingrequireAuth. This left the local auth state (e.g.lastOptionsandaccessToken) uninitialized. When the command's action then proceeded to make API calls (which fallback to the active auth token), the auth client encountered an uninitialized auth state, resulting in a rejected promise with theUnable to refresh authmessage.This PR fixes it by calling
requireAuth(options)at the beginning ofrequirePermissions, ensuring that the auth client and local tokens are always initialized before any early return.Fixes #10879
Scenarios Tested
firestore:locationsunder ADC without an active project (expected behavior: proper GCP API/project error instead of auth failure).firestore:locationsunder ADC with a valid project (expected behavior: lists locations successfully).npm run mocha:fast) to ensure no regressions in auth hooks.Sample Commands
Running without a project (before fix vs after fix):
firebase firestore:locations --debugRunning with a project under ADC:
firebase firestore:locations --project adam-test-c4a4d --debugLists locations successfully.