feat: 优化登录处理逻辑,使用 Promise 处理登录请求,提升代码可读性

This commit is contained in:
2025-09-10 21:52:25 +08:00
parent 8a018a3c55
commit 7a1af795ef

View File

@ -63,14 +63,19 @@ export function LoginForm({
}, [refreshCaptchaKey])
const handleLogin = async (e: React.FormEvent) => {
setIsLogging(true)
e.preventDefault()
try {
const res = await userLogin({ username, password, captcha: captchaToken || "" })
console.log("Login successful:", res)
router.push(redirectBack)
} catch (error) {
console.error("Login failed:", error)
}
userLogin({ username, password, captcha: captchaToken || "" })
.then(res => {
console.log("Login successful:", res)
router.push(redirectBack)
})
.catch(error => {
console.error("Login failed:", error)
})
.finally(() => {
setIsLogging(false)
})
}
const handleCaptchaError = (error: string) => {