From e1eff57c255d5520e1dcb6b205c4f1f05633246e Mon Sep 17 00:00:00 2001 From: Lawrence <142701469+88766lawrence@users.noreply.github.com> Date: Wed, 26 Aug 2026 21:12:52 +0800 Subject: [PATCH] fix(auth): preserve promo codes through OAuth registration --- .../src/components/auth/EmailOAuthButtons.vue | 5 ++++ .../components/auth/LinuxDoOAuthSection.vue | 8 ++++- .../auth/__tests__/EmailOAuthButtons.spec.ts | 30 ++++++++++++++++++- .../auth/__tests__/OAuthLoginSections.spec.ts | 19 ++++++++++++ frontend/src/views/auth/RegisterView.vue | 2 ++ 5 files changed, 62 insertions(+), 2 deletions(-) diff --git a/frontend/src/components/auth/EmailOAuthButtons.vue b/frontend/src/components/auth/EmailOAuthButtons.vue index de45be1449..b59cb8ad2b 100644 --- a/frontend/src/components/auth/EmailOAuthButtons.vue +++ b/frontend/src/components/auth/EmailOAuthButtons.vue @@ -40,6 +40,7 @@ const EMAIL_OAUTH_PENDING_PROVIDER_KEY = 'email_oauth_pending_provider' const props = withDefaults(defineProps<{ disabled?: boolean affCode?: string + promoCode?: string githubEnabled?: boolean googleEnabled?: boolean showDivider?: boolean @@ -83,6 +84,10 @@ function startLogin(provider: EmailOAuthProvider): void { if (affiliateCode) { params.aff_code = affiliateCode } + const promoCode = props.promoCode?.trim() + if (promoCode) { + params.promo_code = promoCode + } emit('start', { provider, params }) } diff --git a/frontend/src/components/auth/LinuxDoOAuthSection.vue b/frontend/src/components/auth/LinuxDoOAuthSection.vue index a8ae927eee..3333b4175c 100644 --- a/frontend/src/components/auth/LinuxDoOAuthSection.vue +++ b/frontend/src/components/auth/LinuxDoOAuthSection.vue @@ -48,6 +48,7 @@ import { resolveAffiliateReferralCode, storeOAuthAffiliateCode } from '@/utils/o const props = withDefaults(defineProps<{ disabled?: boolean affCode?: string + promoCode?: string showDivider?: boolean }>(), { showDivider: true @@ -62,6 +63,11 @@ const { t } = useI18n() function startLogin(): void { const redirectTo = (route.query.redirect as string) || '/dashboard' storeOAuthAffiliateCode(resolveAffiliateReferralCode(props.affCode, route.query.aff, route.query.aff_code)) - emit('start', { provider: 'linuxdo', params: { redirect: redirectTo } }) + const params: Record = { redirect: redirectTo } + const promoCode = props.promoCode?.trim() + if (promoCode) { + params.promo_code = promoCode + } + emit('start', { provider: 'linuxdo', params }) } diff --git a/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts b/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts index 845d763744..86716bf5c7 100644 --- a/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts +++ b/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts @@ -60,6 +60,7 @@ describe('EmailOAuthButtons', () => { props: { githubEnabled: false, googleEnabled: true, + promoCode: ' PROMO-2026 ', }, global: { stubs: { @@ -73,11 +74,38 @@ describe('EmailOAuthButtons', () => { expect(wrapper.emitted('start')?.[0]?.[0]).toEqual({ provider: 'google', - params: { redirect: '/billing?plan=pro', aff_code: 'AFF123' } + params: { + redirect: '/billing?plan=pro', + aff_code: 'AFF123', + promo_code: 'PROMO-2026' + } }) expect(window.location.href).toBe(originalHref) }) + it('omits an empty promo code from the OAuth request', async () => { + const wrapper = mount(EmailOAuthButtons, { + props: { + githubEnabled: true, + googleEnabled: false, + promoCode: ' ', + }, + global: { + stubs: { + GitHubMark: true, + GoogleMark: true, + }, + }, + }) + + await wrapper.get('button').trigger('click') + + expect(wrapper.emitted('start')?.[0]?.[0]).toEqual({ + provider: 'github', + params: { redirect: '/billing?plan=pro', aff_code: 'AFF123' } + }) + }) + it('uses a full-width descriptive button when only GitHub is enabled', () => { const wrapper = mount(EmailOAuthButtons, { props: { diff --git a/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts b/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts index 5111ac6f66..5accbe174e 100644 --- a/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts +++ b/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts @@ -41,4 +41,23 @@ describe('OAuth login sections', () => { expect(window.sessionStorage.getItem('oauth_aff_code')).toBe('AFF456') expect(window.location.href).toBe(originalHref) }) + + it('includes a trimmed promo code in the LinuxDo OAuth request', async () => { + const wrapper = mount(LinuxDoOAuthSection, { + props: { + affCode: 'AFF456', + promoCode: ' PROMO-2026 ' + } + }) + + await wrapper.get('button').trigger('click') + + expect(wrapper.emitted('start')?.[0]?.[0]).toEqual({ + provider: 'linuxdo', + params: { + redirect: '/billing?plan=pro', + promo_code: 'PROMO-2026' + } + }) + }) }) diff --git a/frontend/src/views/auth/RegisterView.vue b/frontend/src/views/auth/RegisterView.vue index c4ccd9c98f..613ab4bd08 100644 --- a/frontend/src/views/auth/RegisterView.vue +++ b/frontend/src/views/auth/RegisterView.vue @@ -284,6 +284,7 @@