fix: reuse auth across clients#1527
Conversation
leahecole
commented
Sep 2, 2025
- 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)
This reverts commit b7ca3fc.
scripts/gen_uber_class.ts
Outdated
| // 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`; |
There was a problem hiding this comment.
Does node require scopes or does it default to the cloud-platform scope?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
yeah, Scopes are already resolved by calling each client scopes method. Ref:
So it already includes the cloud-platform scope.
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
nice, liked the way Auth with API keys was used to check if the auth client is being reused.