fix(auth): 修复登录注册失败无错误提示的问题
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
better-auth 客户端不抛出异常,而是返回 { data, error } 对象
修改错误处理逻辑检查 error 对象而非 try-catch
This commit is contained in:
@@ -38,19 +38,25 @@ export default function LoginPage() {
|
|||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
if (username.includes("@")) {
|
if (username.includes("@")) {
|
||||||
await authClient.signIn.email({
|
const { error } = await authClient.signIn.email({
|
||||||
email: username,
|
email: username,
|
||||||
password: password,
|
password: password,
|
||||||
});
|
});
|
||||||
|
if (error) {
|
||||||
|
toast.error(error.message ?? t("loginFailed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
await authClient.signIn.username({
|
const { error } = await authClient.signIn.username({
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
});
|
});
|
||||||
|
if (error) {
|
||||||
|
toast.error(error.message ?? t("loginFailed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
router.push(redirectTo ?? "/folders");
|
router.push(redirectTo ?? "/folders");
|
||||||
} catch (error) {
|
|
||||||
toast.error(t("loginFailed"));
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,15 +39,17 @@ export default function SignUpPage() {
|
|||||||
|
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
try {
|
try {
|
||||||
await authClient.signUp.email({
|
const { error } = await authClient.signUp.email({
|
||||||
email: email,
|
email: email,
|
||||||
name: username,
|
name: username,
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
});
|
});
|
||||||
|
if (error) {
|
||||||
|
toast.error(error.message ?? t("signUpFailed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
router.push(redirectTo ?? "/folders");
|
router.push(redirectTo ?? "/folders");
|
||||||
} catch (error) {
|
|
||||||
toast.error(t("signUpFailed"));
|
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user