summaryrefslogtreecommitdiff
path: root/packages/core/src/code_assist/oauth2.ts
diff options
context:
space:
mode:
authorMarat Boshernitsan <[email protected]>2025-08-15 22:05:59 -0700
committerGitHub <[email protected]>2025-08-16 05:05:59 +0000
commitbc60257e220a77c2d6e57ea4bfd1f0a483a1344c (patch)
tree6449a959edc2e652e746a25589a8122f2f474ded /packages/core/src/code_assist/oauth2.ts
parent6c1373c33212e26521701acf73c0398721b3a881 (diff)
feat(oauth): Make oauth client a singleton to survive cache failures (#6348)
Diffstat (limited to 'packages/core/src/code_assist/oauth2.ts')
-rw-r--r--packages/core/src/code_assist/oauth2.ts19
1 files changed, 18 insertions, 1 deletions
diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts
index dc1ec490..f9518cbe 100644
--- a/packages/core/src/code_assist/oauth2.ts
+++ b/packages/core/src/code_assist/oauth2.ts
@@ -66,7 +66,9 @@ export interface OauthWebLogin {
loginCompletePromise: Promise<void>;
}
-export async function getOauthClient(
+const oauthClientPromises = new Map<AuthType, Promise<OAuth2Client>>();
+
+async function initOauthClient(
authType: AuthType,
config: Config,
): Promise<OAuth2Client> {
@@ -187,6 +189,16 @@ export async function getOauthClient(
return client;
}
+export async function getOauthClient(
+ authType: AuthType,
+ config: Config,
+): Promise<OAuth2Client> {
+ if (!oauthClientPromises.has(authType)) {
+ oauthClientPromises.set(authType, initOauthClient(authType, config));
+ }
+ return oauthClientPromises.get(authType)!;
+}
+
async function authWithUserCode(client: OAuth2Client): Promise<boolean> {
const redirectUri = 'https://codeassist.google.com/authcode';
const codeVerifier = await client.generateCodeVerifierAsync();
@@ -416,3 +428,8 @@ async function fetchAndCacheUserInfo(client: OAuth2Client): Promise<void> {
console.error('Error retrieving user info:', error);
}
}
+
+// Helper to ensure test isolation
+export function resetOauthClientForTesting() {
+ oauthClientPromises.clear();
+}