fix: preserve promo codes for OAuth signup

This commit is contained in:
Rick
2026-08-26 08:58:22 +08:00
parent 7634e3c23b
commit d522aed65e
5 changed files with 37 additions and 3 deletions
@@ -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 })
}
</script>
@@ -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<string, string> = { redirect: redirectTo }
const promoCode = props.promoCode?.trim()
if (promoCode) {
params.promo_code = promoCode
}
emit('start', { provider: 'linuxdo', params })
}
</script>
@@ -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)
})
@@ -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'
}
})
})
})
+2
View File
@@ -284,6 +284,7 @@
<EmailOAuthButtons
:disabled="registrationActionDisabled"
:aff-code="formData.aff_code"
:promo-code="formData.promo_code"
:github-enabled="githubOAuthEnabled"
:google-enabled="googleOAuthEnabled"
:show-divider="false"
@@ -294,6 +295,7 @@
v-if="linuxdoOAuthEnabled"
:disabled="registrationActionDisabled"
:aff-code="formData.aff_code"
:promo-code="formData.promo_code"
:show-divider="false"
@start="handleOAuthStart"
/>