add errors handlers and translate
This commit is contained in:
+19
-9
@@ -249,9 +249,9 @@ export async function registration(
|
|||||||
error: null
|
error: null
|
||||||
}; */
|
}; */
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
|
const errors: Record<string, string> = {};
|
||||||
if (error) {
|
if (error) {
|
||||||
const typedError = error as any;
|
const typedError = error as any;
|
||||||
const errors: Record<string, string> = {};
|
|
||||||
|
|
||||||
switch (typedError.message_code) {
|
switch (typedError.message_code) {
|
||||||
case 1:
|
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');
|
redirect('/pages/dashboard');
|
||||||
@@ -345,7 +356,7 @@ export async function confirmEmail(
|
|||||||
|
|
||||||
export async function resetPassword(
|
export async function resetPassword(
|
||||||
state: any | undefined,
|
state: any | undefined,
|
||||||
formData: any,
|
formData: FormData,
|
||||||
) {
|
) {
|
||||||
const email = formData.get('email');
|
const email = formData.get('email');
|
||||||
console.log('resetPassword');
|
console.log('resetPassword');
|
||||||
@@ -368,19 +379,20 @@ export async function resetPassword(
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
||||||
const parsed = await response.json();
|
const parsed = await response.json();
|
||||||
console.log(parsed);
|
console.log(parsed);
|
||||||
if (parsed.message_code === 0) {
|
if (parsed.message_code === 0) {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
throw parsed.message_body;
|
throw 'error';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
return {
|
||||||
|
error: error
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
console.log('redirect')
|
||||||
redirect(`/reset-password?email=${email}`);
|
redirect(`/reset-password?email=${email}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,8 +425,6 @@ export async function confirmPassword(
|
|||||||
|
|
||||||
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
|
const validatedFields = SignupFormSchema.safeParse(dataToValidate);
|
||||||
|
|
||||||
console.log(validatedFields);
|
|
||||||
|
|
||||||
if (!validatedFields.success) {
|
if (!validatedFields.success) {
|
||||||
const errors: Record<string, string> = {}
|
const errors: Record<string, string> = {}
|
||||||
JSON.parse(validatedFields.error.message).forEach((obj: {
|
JSON.parse(validatedFields.error.message).forEach((obj: {
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import styles from '@/app/styles/module/login.module.scss'
|
import styles from '@/app/styles/module/login.module.scss'
|
||||||
import { useActionState } from 'react';
|
import { useActionState } from 'react';
|
||||||
|
|
||||||
import { useTranslations } from 'next-intl';
|
import { useTranslations } from 'next-intl';
|
||||||
import { resetPassword } from '@/app/actions/auth';
|
import { resetPassword } from '@/app/actions/auth';
|
||||||
|
|
||||||
@@ -26,19 +25,14 @@ export default function ForgotPasswordForm() {
|
|||||||
className={`${styles['form-input']}`}
|
className={`${styles['form-input']}`}
|
||||||
placeholder={t('enter-email')}
|
placeholder={t('enter-email')}
|
||||||
/>
|
/>
|
||||||
{/* {state === 'error' && (
|
{state?.error === 'error' && (
|
||||||
<p className={`${styles['form-error']}`}>
|
<p className={`${styles['form-error']}`}>
|
||||||
Восстановление пароля не работает
|
{t('register-error-email-invalid')}
|
||||||
</p>
|
</p>
|
||||||
)} */}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{/* {state?.error.server && (
|
|
||||||
<p className={`${styles['form-error']}`}>
|
|
||||||
{t(state?.error.server)}
|
|
||||||
</p>
|
|
||||||
)} */}
|
|
||||||
<button type="submit" className={`${styles['btn']}`}>
|
<button type="submit" className={`${styles['btn']}`}>
|
||||||
Восстановить пароль
|
{t('recover-password')}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -112,14 +112,14 @@ export default function ResetPasswordForm() {
|
|||||||
</div>
|
</div>
|
||||||
<div className={`${styles['form-group']}`}>
|
<div className={`${styles['form-group']}`}>
|
||||||
<label className={`${styles['form-label']} ${styles['required']}`}>
|
<label className={`${styles['form-label']} ${styles['required']}`}>
|
||||||
Код восстановления
|
{t('recovery-code')}
|
||||||
</label>
|
</label>
|
||||||
<input
|
<input
|
||||||
type="readOnly"
|
type="readOnly"
|
||||||
id="verify-token"
|
id="verify-token"
|
||||||
name="verify-token"
|
name="verify-token"
|
||||||
className={`${styles['form-input']}`}
|
className={`${styles['form-input']}`}
|
||||||
placeholder={'Код восстановления'}
|
placeholder={t('recovery-code')}
|
||||||
defaultValue={formState?.previousState?.verifyToken ? formState?.previousState?.verifyToken : ''}
|
defaultValue={formState?.previousState?.verifyToken ? formState?.previousState?.verifyToken : ''}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
@@ -201,7 +201,7 @@ export default function ResetPasswordForm() {
|
|||||||
</p>
|
</p>
|
||||||
)} */}
|
)} */}
|
||||||
<button type="submit" className={`${styles['btn']}`}>
|
<button type="submit" className={`${styles['btn']}`}>
|
||||||
Изменить пароль
|
{t('change-password')}
|
||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -275,6 +275,8 @@
|
|||||||
"confirmation-code": "Confirmation code",
|
"confirmation-code": "Confirmation code",
|
||||||
"enter-confirmation-code": "Enter the confirmation code",
|
"enter-confirmation-code": "Enter the confirmation code",
|
||||||
"personal": "Personal",
|
"personal": "Personal",
|
||||||
"unknown-error": "Unknown error"
|
"unknown-error": "Unknown error",
|
||||||
|
"change-password": "Change Password",
|
||||||
|
"recovery-code": "Recovery code"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -275,6 +275,8 @@
|
|||||||
"confirmation-code": "Код подтверждения",
|
"confirmation-code": "Код подтверждения",
|
||||||
"enter-confirmation-code": "Введите код подтверждения",
|
"enter-confirmation-code": "Введите код подтверждения",
|
||||||
"personal": "Личный",
|
"personal": "Личный",
|
||||||
"unknown-error": "Неизвестная ошибка"
|
"unknown-error": "Неизвестная ошибка",
|
||||||
|
"change-password": "Изменить пароль",
|
||||||
|
"recovery-code": "Код восстановления"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user