diff --git a/vscode/src/services/AuthProvider.ts b/vscode/src/services/AuthProvider.ts index d3ce45978a11..6caac308d689 100644 --- a/vscode/src/services/AuthProvider.ts +++ b/vscode/src/services/AuthProvider.ts @@ -28,6 +28,7 @@ import { localStorage } from './LocalStorageProvider' import { secretStorage } from './SecretStorageProvider' import { telemetryService } from './telemetry' import { telemetryRecorder } from './telemetry-v2' +import { getAuthReferralCode } from './AuthProviderSimplified' type Listener = (authStatus: AuthStatus) => void type Unsubscribe = () => void @@ -35,7 +36,6 @@ type Unsubscribe = () => void export class AuthProvider { private endpointHistory: string[] = [] - private appScheme = vscode.env.uriScheme private client: SourcegraphGraphQLAPIClient | null = null private authStatus: AuthStatus = defaultAuthStatus @@ -396,10 +396,7 @@ export class AuthProvider { } const newTokenCallbackUrl = new URL('/user/settings/tokens/new/callback', endpoint) - newTokenCallbackUrl.searchParams.append( - 'requestFrom', - this.appScheme === 'vscode-insiders' ? 'CODY_INSIDERS' : 'CODY' - ) + newTokenCallbackUrl.searchParams.append('requestFrom', getAuthReferralCode()) this.authStatus.endpoint = endpoint void vscode.env.openExternal(vscode.Uri.parse(newTokenCallbackUrl.href)) } diff --git a/vscode/src/services/AuthProviderSimplified.ts b/vscode/src/services/AuthProviderSimplified.ts index 3c8562926b0d..83e8e64d37e1 100644 --- a/vscode/src/services/AuthProviderSimplified.ts +++ b/vscode/src/services/AuthProviderSimplified.ts @@ -22,19 +22,26 @@ export class AuthProviderSimplified { } } +/** + * Returns a known referral code to use based on the current VS Code environment. + */ +export function getAuthReferralCode(): string { + return ( + { + 'vscode-insiders': 'CODY_INSIDERS', + vscodium: 'CODY_VSCODIUM', + cursor: 'CODY_CURSOR', + }[vscode.env.uriScheme] || 'CODY' + ) +} + // Opens authentication URLs for simplified onboarding. async function openExternalAuthUrl(provider: AuthMethod): Promise { // Create the chain of redirects: // 1. Specific login page (GitHub, etc.) redirects to the post-sign up survey // 2. Post-sign up survery redirects to the new token page // 3. New token page redirects back to the extension with the new token - const uriScheme = vscode.env.uriScheme - const referralCode = - { - 'vscode-insiders': 'CODY_INSIDERS', - vscodium: 'CODY_VSCODIUM', - cursor: 'CODY_CURSOR', - }[uriScheme] || 'CODY' + const referralCode = getAuthReferralCode() const newTokenUrl = `/user/settings/tokens/new/callback?requestFrom=${referralCode}` const postSignUpSurveyUrl = `/post-sign-up?returnTo=${newTokenUrl}` const site = DOTCOM_URL.toString() // Note, ends with the path /