From fdceeb6060c18702af187a8d3a8bc6c63b0c87a2 Mon Sep 17 00:00:00 2001 From: ilya-bkv Date: Thu, 1 Feb 2024 23:34:53 +0300 Subject: [PATCH] refactoring --- src/components/Nav/AuthModal/LoginForm.tsx | 35 +++++++------- src/components/Nav/AuthModal/RegisterForm.tsx | 47 +++++++++---------- src/context/session.tsx | 20 ++++---- src/graphql/client/chat.ts | 1 - 4 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/components/Nav/AuthModal/LoginForm.tsx b/src/components/Nav/AuthModal/LoginForm.tsx index 7e2b1de7..b4b54cda 100644 --- a/src/components/Nav/AuthModal/LoginForm.tsx +++ b/src/components/Nav/AuthModal/LoginForm.tsx @@ -1,7 +1,7 @@ import type { AuthModalSearchParams } from './types' import { clsx } from 'clsx' -import { createSignal, Show } from 'solid-js' +import { createEffect, createSignal, Show } from 'solid-js' import { useLocalize } from '../../../context/localize' import { useSession } from '../../../context/session' @@ -106,26 +106,22 @@ export const LoginForm = () => { setIsSubmitting(true) try { - await signIn({ email: email(), password: password() }) - + const { errors } = await signIn({ email: email(), password: password() }) + if (errors?.length > 0) { + if (errors.some((error) => error.message.includes('bad user credentials'))) { + setValidationErrors((prev) => ({ + ...prev, + password: t('Something went wrong, check email and password'), + })) + } else { + setSubmitError(t('Error')) + } + return + } hideModal() - showSnackbar({ body: t('Welcome!') }) } catch (error) { console.error(error) - if (error instanceof ApiError) { - if (error.code === 'email_not_confirmed') { - setSubmitError(t('Please, confirm email')) - setIsEmailNotConfirmed(true) - - return - } - if (error.code === 'user_not_found') { - setSubmitError(t('Something went wrong, check email and password')) - - return - } - } setSubmitError(error.message) } finally { setIsSubmitting(false) @@ -170,6 +166,11 @@ export const LoginForm = () => { handlePasswordInput(value)} /> + +
+ {validationErrors().password} +
+