mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
feat: 优化登录处理逻辑,使用 Promise 处理登录请求,提升代码可读性
This commit is contained in:
@ -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) => {
|
||||
|
Reference in New Issue
Block a user