add errors handlers and translate

This commit is contained in:
smanylov
2026-02-03 11:44:02 +07:00
parent ab0b68a7b8
commit 8d10aa77c8
5 changed files with 33 additions and 25 deletions
+19 -9
View File
@@ -249,9 +249,9 @@ export async function registration(
error: null
}; */
} catch (error: unknown) {
const errors: Record<string, string> = {};
if (error) {
const typedError = error as any;
const errors: Record<string, string> = {};
switch (typedError.message_code) {
case 1:
@@ -295,7 +295,18 @@ export async function registration(
};
}
throw error;
return {
previousState: {
fullName,
email,
password,
confirm_password,
phone,
companyName,
agree
},
error: errors
};
}
redirect('/pages/dashboard');
@@ -345,7 +356,7 @@ export async function confirmEmail(
export async function resetPassword(
state: any | undefined,
formData: any,
formData: FormData,
) {
const email = formData.get('email');
console.log('resetPassword');
@@ -368,19 +379,20 @@ export async function resetPassword(
});
if (response.ok) {
const parsed = await response.json();
console.log(parsed);
if (parsed.message_code === 0) {
} else {
throw parsed.message_body;
throw 'error';
}
}
} catch (error) {
throw error;
return {
error: error
};
}
console.log('redirect')
redirect(`/reset-password?email=${email}`);
}
@@ -413,8 +425,6 @@ export async function confirmPassword(
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
console.log(validatedFields);
if (!validatedFields.success) {
const errors: Record<string, string> = {}
JSON.parse(validatedFields.error.message).forEach((obj: {