Commit 356b9485 authored by Lorenzo Trujillo Rojas's avatar Lorenzo Trujillo Rojas
Browse files

Merge branch 'main' into 'main'

Se cambió el contexto de autenticación de desarrollo a producción

See merge request !16
parents 9eecacc6 36b66c21
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ const DataContext = createContext<DataContextType>({
export const DataContextProvider = ({ children }: DataContextProviderProps) => {
    const statesDataSource = new StateDataSourceDev();
    const statesRepository = new StateRepositoryImpl(statesDataSource);
    const authDataSource = new AuthDataSourceDev();
    const authDataSource = new AuthDatasourceProd();
    const authRepository = new AuthRepositoryImpl(authDataSource);

    
+16 −12
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import { userRegisterEntityToUserRegisterModel } from "../../utils/prod/user_uti
import { API_URL } from "../../../constants/api";
import { LoginUserModel } from "../../models/prod/login_user_model";
import { UserInfoEntity } from "../../../domain/entities/user_info_entity";
import { RegisterResponseModel } from "../../models/prod/register_user_model";

export class AuthDatasourceProd implements AuthDataSource {
    login: (email: string, password: string) => Promise<LoginInfoEntity> = async (email, password) => {
@@ -14,32 +15,35 @@ export class AuthDatasourceProd implements AuthDataSource {
            password
        };
        //TODO: Hacer el login info model y el user info model cuando se termine la documentación
        const { data, status } = await axios.post<{ token: string, user: UserInfoEntity }>(`${API_URL}/user/signin`, loginInfo);
        if (status !== 200) {
        const { data, status } = await axios.post<RegisterResponseModel>(`${API_URL}/user/signin`, loginInfo);
        if (status !== 201) {
            throw new Error("Error logging in");
        }
        const loginResponse: LoginInfoEntity = {
            token: data.token,
            user: data.user
            token: data.user.token,
            user: {
                id: data.user.userId,
                email: data.user.email,
                name: data.user.name,
                lastName: data.user.lastName,
            }
        }
        return loginResponse;
    };

    register: (user: RegisterInfoEntity) => Promise<LoginInfoEntity> = async (user) => {
        const newUser = userRegisterEntityToUserRegisterModel(user);
        const { data, status } = await axios.post<{ token: string }>(`${API_URL}/user/signup`, newUser);
        //TODO: Falta regresar el id del usuario
        const { data, status } = await axios.post<RegisterResponseModel>(`${API_URL}/user/signup`, newUser);
        if (status !== 201) {
            throw new Error("Error registering user");
        }
        const registeredUser: LoginInfoEntity = {
            token: data.token,
            token: data.user.token,
            user: {
                id: 1,
                email: newUser.email,
                name: newUser.name,
                lastName: newUser.lastName,
                birthDate: new Date(newUser.birthDate)
                id: data.user.userId,
                email: data.user.email,
                name: data.user.name,
                lastName: data.user.lastName
            }
        }
        return registeredUser;
+10 −0
Original line number Diff line number Diff line
@@ -5,3 +5,13 @@ export interface RegisterUserModel {
    lastName: string;
    birthDate: string;
}

export interface RegisterResponseModel {
    user: {
        userId: number;
        email: string;
        name: string;
        lastName: string;
        token: string;
    }
}
 No newline at end of file