From 9975aec5d2619114b32feb57e78516b9983c7181 Mon Sep 17 00:00:00 2001 From: Lorenzo Trujillo Date: Thu, 18 Apr 2024 10:49:50 -0600 Subject: [PATCH 1/3] =?UTF-8?q?Se=20agreg=C3=B3=20un=20manejo=20de=20error?= =?UTF-8?q?es=20en=20el=20formulario=20de=20loggin?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile/src/hooks/useLoggin.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/mobile/src/hooks/useLoggin.ts b/mobile/src/hooks/useLoggin.ts index 8154a496..379452da 100644 --- a/mobile/src/hooks/useLoggin.ts +++ b/mobile/src/hooks/useLoggin.ts @@ -1,4 +1,4 @@ -import { useForm } from "react-hook-form" +import { set, useForm } from "react-hook-form" import { useAuth } from "../contexts/auth_context"; import { Navigator, Redirect, router } from "expo-router"; import { useDataContext } from "../contexts/data_context"; @@ -9,7 +9,7 @@ export type LoginFormValues = { } export const useLoggin = () => { - const { control, handleSubmit, formState: { errors } } = useForm(); + const { control, handleSubmit, formState: { errors }, setError } = useForm(); const { authRepository } = useDataContext(); const { login } = useAuth(); @@ -18,8 +18,16 @@ export const useLoggin = () => { const { user, token } = await authRepository!.login(data.email, data.password); await login(user, token); router.replace('/(tabs)'); - } catch (error) { - console.log(error); + } catch (error: any) { + switch (error.response.status) { + case 401: + setError('email', { type: 'manual', message: 'Invalid email or password' }); + setError('password', { type: 'manual', message: 'Invalid email or password' }); + break; + default: + console.log('Something went wrong'); + break; + } } } -- GitLab From b991c6283ab8b91360f1d28ee3302558fb17bba7 Mon Sep 17 00:00:00 2001 From: Lorenzo Trujillo Date: Thu, 18 Apr 2024 10:50:00 -0600 Subject: [PATCH 2/3] =?UTF-8?q?Se=20agreg=C3=B3=20un=20manejo=20de=20error?= =?UTF-8?q?es=20en=20el=20formulario=20de=20signup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mobile/src/hooks/useSignUp.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/mobile/src/hooks/useSignUp.ts b/mobile/src/hooks/useSignUp.ts index fde3786b..07c89333 100644 --- a/mobile/src/hooks/useSignUp.ts +++ b/mobile/src/hooks/useSignUp.ts @@ -34,8 +34,15 @@ export const useSignUp = () => { const { user, token } = await authRepository!.register(userToRegister); await login(user, token); router.replace("/(tabs)"); - } catch (error) { - console.log(error); + } catch (error: any) { + switch (error.response.status) { + case 400: + setError("email", { type: "manual", message: "Email already in use" }); + break; + default: + console.log("Something went wrong"); + break; + } } } -- GitLab From f9a2f4c9fea03398f64c41aa51e003abbda4249f Mon Sep 17 00:00:00 2001 From: Lorenzo Trujillo Date: Thu, 18 Apr 2024 10:50:31 -0600 Subject: [PATCH 3/3] Se aplicaron los cambios en el manejo de errores en el componente --- mobile/src/components/sign_up_form/sign_up_form.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mobile/src/components/sign_up_form/sign_up_form.tsx b/mobile/src/components/sign_up_form/sign_up_form.tsx index b22fb9a1..33c0a12a 100644 --- a/mobile/src/components/sign_up_form/sign_up_form.tsx +++ b/mobile/src/components/sign_up_form/sign_up_form.tsx @@ -32,7 +32,7 @@ export const SignUpForm = () => { value={value} onChangeText={onChange} onBlur={onBlur} - errors={errors.email?.message as string} + errors={errors.name?.message as string} /> )} rules={{ @@ -52,7 +52,7 @@ export const SignUpForm = () => { value={value} onChangeText={onChange} onBlur={onBlur} - errors={errors.email?.message as string} + errors={errors.lastName?.message as string} /> )} rules={{ @@ -113,7 +113,7 @@ export const SignUpForm = () => { value={value} onChangeText={onChange} onBlur={onBlur} - errors={errors.password?.message as string} + errors={errors.confirmPassword?.message as string} /> )} rules={{ required: "Confirm password is required" }} -- GitLab