fix(auth): 修复登录注册失败无错误提示的问题
All checks were successful
continuous-integration/drone/push Build is passing

better-auth 客户端不抛出异常,而是返回 { data, error } 对象
修改错误处理逻辑检查 error 对象而非 try-catch
This commit is contained in:
2026-03-09 19:52:41 +08:00
parent 11a265d52e
commit 436d58be52
2 changed files with 15 additions and 7 deletions

View File

@@ -38,19 +38,25 @@ export default function LoginPage() {
setLoading(true);
try {
if (username.includes("@")) {
await authClient.signIn.email({
const { error } = await authClient.signIn.email({
email: username,
password: password,
});
if (error) {
toast.error(error.message ?? t("loginFailed"));
return;
}
} else {
await authClient.signIn.username({
const { error } = await authClient.signIn.username({
username: username,
password: password,
});
if (error) {
toast.error(error.message ?? t("loginFailed"));
return;
}
}
router.push(redirectTo ?? "/folders");
} catch (error) {
toast.error(t("loginFailed"));
} finally {
setLoading(false);
}

View File

@@ -39,15 +39,17 @@ export default function SignUpPage() {
setLoading(true);
try {
await authClient.signUp.email({
const { error } = await authClient.signUp.email({
email: email,
name: username,
username: username,
password: password,
});
if (error) {
toast.error(error.message ?? t("signUpFailed"));
return;
}
router.push(redirectTo ?? "/folders");
} catch (error) {
toast.error(t("signUpFailed"));
} finally {
setLoading(false);
}