Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

fix: reuse auth across clients#1527

Merged
leahecole merged 15 commits intogoogleapis:preview-9.xfrom
leahecole:auth
Sep 8, 2025
Merged

fix: reuse auth across clients#1527
leahecole merged 15 commits intogoogleapis:preview-9.xfrom
leahecole:auth

Conversation

@leahecole
Copy link
Contributor

  • adds logic to not reinitialize auth every time based on feedback from @tswast
  • adds a line to the package.json to delete the generation script .js file when it's done (causes lint issues, not needed after generation is done)

@leahecole leahecole requested review from a team as code owners September 2, 2025 22:27
@product-auto-label product-auto-label bot added size: s Pull request size is small. api: bigquery Issues related to the googleapis/nodejs-bigquery API. labels Sep 2, 2025
// and doesn't need to be re initialized each time
subClientOptions = subClientOptions || {};
subClientOptions.opts = subClientOptions.opts || {};
subClientOptions.opts.auth = subClientOptions.opts.auth || new GoogleAuth();\n\n`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does node require scopes or does it default to the cloud-platform scope?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node does not require them, they can be passed optionally but also iiuc, defaultScopes are set as part of client initialization (example) - I am fuzzy on how this staticMembers.scopes gets populated (I should learn). In gax, this gets initialized with certain options that are passed in - this call to gax - I should probably update this to make sure that when we initialize a new client, we're passing in the options that would have made their way to gax and that nothing is missing.

Thoughts @alvarowolfx ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, Scopes are already resolved by calling each client scopes method. Ref:

static get scopes() {

So it already includes the cloud-platform scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Talked to Alvaro on chat - did a small refactor to instead create one client, then use whatever auth that client has and pass it to the remaining clients.

If a user passes auth in, that will be used by the first client, and therefore will also be picked up by the subsequent clients.

If they don't, auth will be created by default in that call to gax that I linked, and we are picking up the defaults set there and passing them to the other clients. If we did not do this, Alvaro correctly pointed out we'd be needing to keep this code up to date with gax - this way, we don't

alvarowolfx
alvarowolfx previously approved these changes Sep 3, 2025
@product-auto-label product-auto-label bot added size: m Pull request size is medium. and removed size: s Pull request size is small. labels Sep 5, 2025
@leahecole leahecole added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Sep 5, 2025
Copy link
Contributor

@alvarowolfx alvarowolfx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, liked the way Auth with API keys was used to check if the auth client is being reused.

@leahecole leahecole merged commit 0d7e16f into googleapis:preview-9.x Sep 8, 2025
15 of 16 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: bigquery Issues related to the googleapis/nodejs-bigquery API. kokoro:force-run Add this label to force Kokoro to re-run the tests. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments