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]) }, [refreshCaptchaKey])
const handleLogin = async (e: React.FormEvent) => { const handleLogin = async (e: React.FormEvent) => {
setIsLogging(true)
e.preventDefault() e.preventDefault()
try { userLogin({ username, password, captcha: captchaToken || "" })
const res = await userLogin({ username, password, captcha: captchaToken || "" }) .then(res => {
console.log("Login successful:", res) console.log("Login successful:", res)
router.push(redirectBack) router.push(redirectBack)
} catch (error) { })
console.error("Login failed:", error) .catch(error => {
} console.error("Login failed:", error)
})
.finally(() => {
setIsLogging(false)
})
} }
const handleCaptchaError = (error: string) => { const handleCaptchaError = (error: string) => {