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..a7e5dc54a1 100644 --- a/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts +++ b/frontend/src/components/auth/__tests__/EmailOAuthButtons.spec.ts @@ -33,6 +33,7 @@ describe('EmailOAuthButtons', () => { props: { githubEnabled: true, googleEnabled: false, + promoCode: ' PROMO123 ', }, global: { stubs: { @@ -47,7 +48,7 @@ describe('EmailOAuthButtons', () => { expect(wrapper.emitted('start')).toEqual([[ { provider: 'github', - params: { redirect: '/billing?plan=pro', aff_code: 'AFF123' } + params: { redirect: '/billing?plan=pro', aff_code: 'AFF123', promo_code: 'PROMO123' } } ]]) expect(window.sessionStorage.getItem('oauth_aff_code')).toBe('AFF123') @@ -60,6 +61,7 @@ describe('EmailOAuthButtons', () => { props: { githubEnabled: false, googleEnabled: true, + promoCode: 'PROMO456', }, global: { stubs: { @@ -73,7 +75,7 @@ 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: 'PROMO456' } }) expect(window.location.href).toBe(originalHref) }) diff --git a/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts b/frontend/src/components/auth/__tests__/OAuthLoginSections.spec.ts index 5111ac6f66..897d78e9aa 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: ' PROMO789 ' + } + }) + + await wrapper.get('button').trigger('click') + + expect(wrapper.emitted('start')?.[0]?.[0]).toEqual({ + provider: 'linuxdo', + params: { + redirect: '/billing?plan=pro', + promo_code: 'PROMO789' + } + }) + }) }) 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 @@