diff --git a/packages/core/src/code_assist/oauth2.ts b/packages/core/src/code_assist/oauth2.ts index 0540ff4565..b5a51ad0ee 100644 --- a/packages/core/src/code_assist/oauth2.ts +++ b/packages/core/src/code_assist/oauth2.ts @@ -117,12 +117,6 @@ async function initOauthClient( authType: AuthType, config: Config, ): Promise { - const recordGoogleAuthEndIfApplicable = () => { - if (authType === AuthType.LOGIN_WITH_GOOGLE) { - recordGoogleAuthEnd(config); - } - }; - const credentials = await fetchCachedCredentials(); if ( @@ -167,6 +161,9 @@ async function initOauthClient( access_token: process.env['GOOGLE_CLOUD_ACCESS_TOKEN'], }); await fetchAndCacheUserInfo(client); + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + recordGoogleAuthEnd(config); + } return client; } @@ -203,7 +200,9 @@ async function initOauthClient( debugLogger.log('Loaded cached credentials.'); await triggerPostAuthCallbacks(credentials as Credentials); - recordGoogleAuthEndIfApplicable(); + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + recordGoogleAuthEnd(config); + } return client; } } catch (error) { @@ -295,7 +294,9 @@ async function initOauthClient( } await triggerPostAuthCallbacks(client.credentials); - recordGoogleAuthEndIfApplicable(); + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + recordGoogleAuthEnd(config); + } } else { // In ACP mode, we skip the interactive consent and directly open the browser if (!config.getAcpMode()) { @@ -402,7 +403,9 @@ async function initOauthClient( }); await triggerPostAuthCallbacks(client.credentials); - recordGoogleAuthEndIfApplicable(); + if (authType === AuthType.LOGIN_WITH_GOOGLE) { + recordGoogleAuthEnd(config); + } } return client;