Loading mobile/src/components/sign_up_form/sign_up_form.tsx +3 −3 Original line number Diff line number Diff line Loading @@ -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={{ Loading @@ -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={{ Loading Loading @@ -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" }} Loading mobile/src/contexts/data_context.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading mobile/src/hooks/useLoggin.ts +12 −4 Original line number Diff line number Diff line 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"; Loading @@ -9,7 +9,7 @@ export type LoginFormValues = { } export const useLoggin = () => { const { control, handleSubmit, formState: { errors } } = useForm<LoginFormValues>(); const { control, handleSubmit, formState: { errors }, setError } = useForm<LoginFormValues>(); const { authRepository } = useDataContext(); const { login } = useAuth(); Loading @@ -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; } } } Loading mobile/src/hooks/useSignUp.ts +9 −2 Original line number Diff line number Diff line Loading @@ -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; } } } Loading mobile/src/infrastructure/datasource/prod/auth_datasource.ts +16 −12 Original line number Diff line number Diff line Loading @@ -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) => { Loading @@ -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; Loading Loading
mobile/src/components/sign_up_form/sign_up_form.tsx +3 −3 Original line number Diff line number Diff line Loading @@ -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={{ Loading @@ -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={{ Loading Loading @@ -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" }} Loading
mobile/src/contexts/data_context.tsx +1 −1 Original line number Diff line number Diff line Loading @@ -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); Loading
mobile/src/hooks/useLoggin.ts +12 −4 Original line number Diff line number Diff line 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"; Loading @@ -9,7 +9,7 @@ export type LoginFormValues = { } export const useLoggin = () => { const { control, handleSubmit, formState: { errors } } = useForm<LoginFormValues>(); const { control, handleSubmit, formState: { errors }, setError } = useForm<LoginFormValues>(); const { authRepository } = useDataContext(); const { login } = useAuth(); Loading @@ -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; } } } Loading
mobile/src/hooks/useSignUp.ts +9 −2 Original line number Diff line number Diff line Loading @@ -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; } } } Loading
mobile/src/infrastructure/datasource/prod/auth_datasource.ts +16 −12 Original line number Diff line number Diff line Loading @@ -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) => { Loading @@ -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; Loading