From ef1e0e4b86651a5e3c5801fc1642d4ecbd59297a Mon Sep 17 00:00:00 2001 From: qwqcode Date: Tue, 3 Sep 2024 11:37:00 +0800 Subject: [PATCH] fix(auth): email verify code send button --- ui/plugin-auth/DialogMain.tsx | 1 + ui/plugin-auth/VerifyButton.tsx | 56 +++++++++++++++++++-------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/ui/plugin-auth/DialogMain.tsx b/ui/plugin-auth/DialogMain.tsx index 39032941..6c59da1d 100644 --- a/ui/plugin-auth/DialogMain.tsx +++ b/ui/plugin-auth/DialogMain.tsx @@ -34,6 +34,7 @@ export const DialogMain = (props: DialogMainProps) => { ) .catch((e) => { alert('Failed to fetch login methods: ' + e.message) + onClose() return [] }) }) diff --git a/ui/plugin-auth/VerifyButton.tsx b/ui/plugin-auth/VerifyButton.tsx index a1c81f23..c704ba71 100644 --- a/ui/plugin-auth/VerifyButton.tsx +++ b/ui/plugin-auth/VerifyButton.tsx @@ -11,36 +11,44 @@ export const VerifyButton = (props: VerifyButtonProps) => { const { ctx, onSend, getEmail } = props const [btnText, setBtnText] = createSignal(ctx.$t('verifySend')) + const TIMEOUT = 60 + let sent = false let timer: any = null - let duration = 60 - const clickHandler = () => { + let duration = TIMEOUT + + const reset = () => { + timer && clearInterval(timer) + timer = null + sent = false + duration = TIMEOUT + } + + const clickHandler = async () => { if (sent) return sent = true - ctx - .getApi() - .auth.sendVerifyEmail({ + + try { + await ctx.getApi().auth.sendVerifyEmail({ email: getEmail(), }) - .then(() => { - timer && clearInterval(timer) - timer = setInterval(() => { - if (duration <= 0) { - clearInterval(timer) - setBtnText(ctx.$t('verifyResend')) - sent = false - return - } - duration-- - setBtnText(ctx.$t('waitSeconds', { seconds: `${duration}` })) - }, 1000) - onSend?.() - }) - .catch((e) => { - sent = false - // console.log(e.message) - alert(e.message) - }) + + timer && clearInterval(timer) + timer = setInterval(() => { + if (duration <= 0) { + reset() + setBtnText(ctx.$t('verifyResend')) + return + } + duration-- + setBtnText(ctx.$t('waitSeconds', { seconds: `${duration}` })) + }, 1000) + onSend?.() + } catch (e: any) { + sent = false + // console.log(e.message) + alert(e.message) + } } return (