diff --git a/src/app/actions/auth.ts b/src/app/actions/auth.ts index 71070a1..17ac69e 100644 --- a/src/app/actions/auth.ts +++ b/src/app/actions/auth.ts @@ -92,14 +92,31 @@ export async function authorization( }); if (response.ok) { let parsed = await response.json(); - await createSession(parsed.message_body.token, email); + if (parsed.message_desc === 'Operation successful') { + await createSession(parsed.message_body.token, email); + } else { + throw (`${parsed.message_code}`); + } } else { throw ('request-ended-with-an-error'); } } catch (error) { const errors: Record = {} - errors['server'] = `${error}`; + + switch (error) { + case '2': + errors['server'] = 'password-does-not-match' + break; + + case '4': + errors['server'] = 'email-not-found' + break; + + default: + errors['server'] = 'request-ended-with-an-error' + break; + } if (error) { return { @@ -198,22 +215,28 @@ export async function registration( } }); - console.log('--response--'); - console.log(response); - console.log('--response--'); - if (response.ok) { let parsed = await response.json(); - console.log('--parsed--'); - console.log(parsed); - await createSession(parsed.message_body.token, email); + if (parsed.message_desc === 'Operation successful') { + await createSession(parsed.message_body.token, email); + } else { + throw (`${parsed.message_code}`); + } } else { throw (`${response.status}`); } } catch (error) { if (error) { const errors: Record = {}; - errors['server'] = 'request-ended-with-an-error' + switch (error) { + case '1': + errors['server'] = 'email-already-registered' + break; + + default: + errors['server'] = 'request-ended-with-an-error' + break; + } return { previousState: { diff --git a/src/app/ui/forms/register-form.tsx b/src/app/ui/forms/register-form.tsx index e527dfe..840a5f4 100644 --- a/src/app/ui/forms/register-form.tsx +++ b/src/app/ui/forms/register-form.tsx @@ -217,7 +217,7 @@ export default function RegisterForm() {

)} {state?.error?.server && ( -

+

{t(state?.error?.server)}

)} diff --git a/src/app/ui/nav-link-dropdown.tsx b/src/app/ui/nav-link-dropdown.tsx index 70cc2e5..364c242 100644 --- a/src/app/ui/nav-link-dropdown.tsx +++ b/src/app/ui/nav-link-dropdown.tsx @@ -7,8 +7,6 @@ import { useTranslations } from 'next-intl'; export default function DropDownList() { const pathname = usePathname().replace('/en/', '/').replace('/ru/', '/'); - console.log('pathname'); - console.log(pathname); const [dropDownExpanded, setDropDownExpanded] = useState(false); const t = useTranslations('Global'); diff --git a/src/i18n/messages/en.json b/src/i18n/messages/en.json index 66a94c1..63c5c44 100644 --- a/src/i18n/messages/en.json +++ b/src/i18n/messages/en.json @@ -113,6 +113,9 @@ "request-ended-with-an-error": "The request ended with an error", "safe-storage": "Reliable storage and data security", "sign-in": "Sign in", - "terms-of-use": "terms of use" + "terms-of-use": "terms of use", + "email-already-registered": "Email already registered", + "password-does-not-match" : "Password does not match", + "email-not-found": "Email not found" } } \ No newline at end of file diff --git a/src/i18n/messages/ru.json b/src/i18n/messages/ru.json index 2ddde03..febf7ce 100644 --- a/src/i18n/messages/ru.json +++ b/src/i18n/messages/ru.json @@ -113,6 +113,9 @@ "request-ended-with-an-error": "Запрос завершился с ошибкой", "safe-storage": "Надежное хранение и безопасность данных", "sign-in": "Войти в систему", - "terms-of-use": "условиями использования" + "terms-of-use": "условиями использования", + "email-already-registered": "Такой Email уже зарегистрирован", + "password-does-not-match" : "Пароль не совпадает", + "email-not-found": "Email не найден" } } \ No newline at end of file