add errors handlers and translate
This commit is contained in:
+19
-9
@@ -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: {
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
import styles from '@/app/styles/module/login.module.scss'
|
||||
import { useActionState } from 'react';
|
||||
|
||||
import { useTranslations } from 'next-intl';
|
||||
import { resetPassword } from '@/app/actions/auth';
|
||||
|
||||
@@ -26,19 +25,14 @@ export default function ForgotPasswordForm() {
|
||||
className={`${styles['form-input']}`}
|
||||
placeholder={t('enter-email')}
|
||||
/>
|
||||
{/* {state === 'error' && (
|
||||
{state?.error === 'error' && (
|
||||
<p className={`${styles['form-error']}`}>
|
||||
Восстановление пароля не работает
|
||||
{t('register-error-email-invalid')}
|
||||
</p>
|
||||
)} */}
|
||||
)}
|
||||
</div>
|
||||
{/* {state?.error.server && (
|
||||
<p className={`${styles['form-error']}`}>
|
||||
{t(state?.error.server)}
|
||||
</p>
|
||||
)} */}
|
||||
<button type="submit" className={`${styles['btn']}`}>
|
||||
Восстановить пароль
|
||||
{t('recover-password')}
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
|
||||
@@ -112,14 +112,14 @@ export default function ResetPasswordForm() {
|
||||
</div>
|
||||
<div className={`${styles['form-group']}`}>
|
||||
<label className={`${styles['form-label']} ${styles['required']}`}>
|
||||
Код восстановления
|
||||
{t('recovery-code')}
|
||||
</label>
|
||||
<input
|
||||
type="readOnly"
|
||||
id="verify-token"
|
||||
name="verify-token"
|
||||
className={`${styles['form-input']}`}
|
||||
placeholder={'Код восстановления'}
|
||||
placeholder={t('recovery-code')}
|
||||
defaultValue={formState?.previousState?.verifyToken ? formState?.previousState?.verifyToken : ''}
|
||||
/>
|
||||
</div>
|
||||
@@ -201,7 +201,7 @@ export default function ResetPasswordForm() {
|
||||
</p>
|
||||
)} */}
|
||||
<button type="submit" className={`${styles['btn']}`}>
|
||||
Изменить пароль
|
||||
{t('change-password')}
|
||||
</button>
|
||||
</form>
|
||||
)
|
||||
|
||||
@@ -275,6 +275,8 @@
|
||||
"confirmation-code": "Confirmation code",
|
||||
"enter-confirmation-code": "Enter the confirmation code",
|
||||
"personal": "Personal",
|
||||
"unknown-error": "Unknown error"
|
||||
"unknown-error": "Unknown error",
|
||||
"change-password": "Change Password",
|
||||
"recovery-code": "Recovery code"
|
||||
}
|
||||
}
|
||||
@@ -275,6 +275,8 @@
|
||||
"confirmation-code": "Код подтверждения",
|
||||
"enter-confirmation-code": "Введите код подтверждения",
|
||||
"personal": "Личный",
|
||||
"unknown-error": "Неизвестная ошибка"
|
||||
"unknown-error": "Неизвестная ошибка",
|
||||
"change-password": "Изменить пароль",
|
||||
"recovery-code": "Код восстановления"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user