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 b22fb9a185fa85bdd64eb44401553ddbe18de7fa..33c0a12a08d7fb2dc62834418b427ec6523562cf 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" }} diff --git a/mobile/src/hooks/useLoggin.ts b/mobile/src/hooks/useLoggin.ts index 8154a496b7d5d642682dc6108ee488bb7de74bc6..379452daf03df273422fd5b24b44f58b3047e498 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; + } } } diff --git a/mobile/src/hooks/useSignUp.ts b/mobile/src/hooks/useSignUp.ts index fde3786b616646bfa28b0711e91fd702b9292ffa..07c8933347d090b03d5b274ac54e53cc22bbd42c 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; + } } }