mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-10-20 00:18:55 +00:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user