Merge pull request #7728 from ouchihao/codex/bug-oauth-code-unmount

fix(auth): avoid starting OAuth code cooldowns after unmount
This commit is contained in:
Wesley Liddick
2026-10-08 13:51:30 +08:00
committed by GitHub
2 changed files with 27 additions and 0 deletions
@@ -168,6 +168,7 @@ const captchaEnabled = computed(
)
let countdownTimer: ReturnType<typeof setInterval> | null = null
let disposed = false
watch(
() => props.initialEmail,
@@ -288,6 +289,7 @@ async function handleSendCode() {
tencent_captcha_ticket: tencentCaptchaEnabled.value ? turnstileToken.value : undefined,
tencent_captcha_randstr: tencentCaptchaEnabled.value ? tencentCaptchaRandstr.value : undefined
})
if (disposed) return
sendCodeSuccess.value = true
startCountdown(response.countdown)
} catch (error: unknown) {
@@ -373,6 +375,7 @@ onMounted(async () => {
})
onUnmounted(() => {
disposed = true
clearCountdown()
})
</script>
@@ -51,6 +51,30 @@ describe('PendingOAuthCreateAccountForm', () => {
})
})
it('does not restart the code cooldown after switching away during a send', async () => {
vi.useFakeTimers()
let finish!: (value: { countdown: number }) => void
sendPendingOAuthVerifyCode.mockImplementation(() => new Promise(resolve => { finish = resolve }))
const wrapper = mount(PendingOAuthCreateAccountForm, {
props: { testIdPrefix: 'oidc', initialEmail: 'user@example.com', isSubmitting: false },
global: { stubs: { TurnstileWidget: true } },
})
try {
await flushPromises()
await wrapper.get('[data-testid="oidc-create-account-send-code"]').trigger('click')
await flushPromises()
expect(sendPendingOAuthVerifyCode).toHaveBeenCalledTimes(1)
wrapper.unmount()
finish({ countdown: 60 })
await flushPromises()
expect(vi.getTimerCount()).toBe(0)
} finally {
wrapper.unmount()
vi.clearAllTimers()
vi.useRealTimers()
}
})
it('acquires separate proofs for pending OAuth send-code and create-account', async () => {
getPublicSettings.mockResolvedValue({
email_verify_enabled: true,