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