Skip to content

Commit

Permalink
fix(auth): correct email verification code send button
Browse files Browse the repository at this point in the history
  • Loading branch information
qwqcode committed Sep 3, 2024
1 parent f29d2f8 commit e619110
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 24 deletions.
1 change: 1 addition & 0 deletions ui/plugin-auth/DialogMain.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const DialogMain = (props: DialogMainProps) => {
)
.catch((e) => {
alert('Failed to fetch login methods: ' + e.message)
onClose()
return []
})
})
Expand Down
56 changes: 32 additions & 24 deletions ui/plugin-auth/VerifyButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit e619110

Please sign in to comment.