修复登录问题
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-12-12 16:45:50 +08:00
parent ff0954a413
commit e17437a5ad
3 changed files with 105 additions and 15 deletions

View File

@@ -26,6 +26,36 @@ export async function signUpAction(prevState: SignUpState, formData: FormData) {
const password = formData.get("password") as string;
const redirectTo = formData.get("redirectTo") as string;
// 服务器端验证
const errors: SignUpState['errors'] = {};
if (!email) {
errors.email = ["邮箱是必填项"];
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
errors.email = ["请输入有效的邮箱地址"];
}
if (!name) {
errors.username = ["姓名是必填项"];
} else if (name.length < 2) {
errors.username = ["姓名至少需要2个字符"];
}
if (!password) {
errors.password = ["密码是必填项"];
} else if (password.length < 8) {
errors.password = ["密码至少需要8个字符"];
}
// 如果有验证错误,返回错误状态
if (Object.keys(errors).length > 0) {
return {
success: false,
message: "请修正表单中的错误",
errors
};
}
try {
await auth.api.signUpEmail({
body: {
@@ -49,6 +79,28 @@ export async function signInAction(prevState: SignUpState, formData: FormData) {
const password = formData.get("password") as string;
const redirectTo = formData.get("redirectTo") as string;
// 服务器端验证
const errors: SignUpState['errors'] = {};
if (!email) {
errors.email = ["邮箱是必填项"];
} else if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) {
errors.email = ["请输入有效的邮箱地址"];
}
if (!password) {
errors.password = ["密码是必填项"];
}
// 如果有验证错误,返回错误状态
if (Object.keys(errors).length > 0) {
return {
success: false,
message: "请修正表单中的错误",
errors
};
}
try {
await auth.api.signInEmail({
body: {