Commit 3831121f authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Se conectó el login con los repositorios

parent 0cfe9f3e
Loading
Loading
Loading
Loading
+9 −8
Original line number Diff line number Diff line
import { useForm } from "react-hook-form"
import { useAuth } from "../contexts/auth_context";
import { Navigator, Redirect, router } from "expo-router";
import { useDataContext } from "../contexts/data_context";

export type LoginFormValues = {
    email: string;
@@ -9,17 +10,17 @@ export type LoginFormValues = {

export const useLoggin = () => {
    const { control, handleSubmit, formState: { errors } } = useForm<LoginFormValues>();
    const { authRepository } = useDataContext();
    const { login } = useAuth();

    const validSubmit = async (data: LoginFormValues) => {
        await login({
            id: 1,
            email: data.email,
            name: 'John',
            lastName: 'Doe',
            birthDate: '1990-01-01'
        }, 'hola');
        try {
            const { user, token } = await authRepository!.login(data.email, data.password);
            await login(user, token);
            router.replace('/(tabs)');
        } catch (error) {
            console.log(error);
        }
    }

    const invalidSubmit = (errors: any) => {