mirror of
https://github.com/snowykami/neo-blog.git
synced 2025-09-26 11:06:23 +00:00
fix: Closes #6 优化登录时的状态反馈,且登录失败后会刷新验证码
This commit is contained in:
@ -49,7 +49,7 @@ func (s *UserService) UserLogin(req *dto.UserLoginReq) (*dto.UserLoginResp, erro
|
||||
}
|
||||
return resp, nil
|
||||
} else {
|
||||
return nil, errs.ErrInternalServer
|
||||
return nil, errs.New(http.StatusUnauthorized, "Invalid username or password", nil)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -20,6 +20,7 @@ import { useRouter, useSearchParams } from "next/navigation"
|
||||
import { useTranslations } from "next-intl"
|
||||
import Captcha from "../common/captcha"
|
||||
import { CaptchaProvider } from "@/models/captcha"
|
||||
import { toast } from "sonner"
|
||||
|
||||
export function LoginForm({
|
||||
className,
|
||||
@ -47,7 +48,7 @@ export function LoginForm({
|
||||
setOidcConfigs(res.data || []) // 确保是数组
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching OIDC configs:", error)
|
||||
toast.error(t("fetch_oidc_configs_failed") + (error?.message ? `: ${error.message}` : ""))
|
||||
setOidcConfigs([]) // 错误时设置为空数组
|
||||
})
|
||||
}, [])
|
||||
@ -58,7 +59,8 @@ export function LoginForm({
|
||||
setCaptchaProps(res.data)
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error fetching captcha config:", error)
|
||||
toast.error(t("fetch_captcha_config_failed") + (error?.message ? `: ${error.message}` : ""))
|
||||
setCaptchaProps(null)
|
||||
})
|
||||
}, [refreshCaptchaKey])
|
||||
|
||||
@ -67,11 +69,14 @@ export function LoginForm({
|
||||
e.preventDefault()
|
||||
userLogin({ username, password, captcha: captchaToken || "" })
|
||||
.then(res => {
|
||||
console.log("Login successful:", res)
|
||||
toast.success(t("login_success") + ` ${res.data.user.nickname || res.data.user.username}`);
|
||||
router.push(redirectBack)
|
||||
})
|
||||
.catch(error => {
|
||||
console.error("Login failed:", error)
|
||||
console.log(error)
|
||||
toast.error(t("login_failed") + (error?.response?.data?.message ? `: ${error.response.data.message}` : ""))
|
||||
setRefreshCaptchaKey(k => k + 1)
|
||||
setCaptchaToken(null)
|
||||
})
|
||||
.finally(() => {
|
||||
setIsLogging(false)
|
||||
|
@ -56,7 +56,11 @@
|
||||
},
|
||||
"Login": {
|
||||
"captcha_error": "验证错误,请重试。",
|
||||
"fetch_captcha_config_failed": "获取验证码失败,请稍后重试。",
|
||||
"fetch_oidc_configs_failed": "获取第三方身份提供者配置失败。",
|
||||
"logging": "正在登录...",
|
||||
"login_success": "登录成功!",
|
||||
"login_failed": "登录失败",
|
||||
"welcome": "欢迎回来",
|
||||
"with_oidc": "使用第三方身份提供者",
|
||||
"or_continue_with_local_account": "或使用用户名和密码",
|
||||
@ -69,7 +73,6 @@
|
||||
"by_logging_in_you_agree_to_our": "登录即表示你同意我们的",
|
||||
"terms_of_service": "服务条款",
|
||||
"and": "和",
|
||||
"privacy_policy": "隐私政策",
|
||||
"login_failed": "登录失败,请检查你的凭据。"
|
||||
"privacy_policy": "隐私政策"
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user