From 6aede83b39f1050b7528b243278a85e5623856be Mon Sep 17 00:00:00 2001 From: Alberto Duarte Delgado Date: Mon, 30 Mar 2026 14:59:30 +0100 Subject: Integracion Firebase --- src/features/auth/hooks/useLogin.ts | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/features/auth/hooks/useLogin.ts (limited to 'src/features/auth/hooks/useLogin.ts') diff --git a/src/features/auth/hooks/useLogin.ts b/src/features/auth/hooks/useLogin.ts new file mode 100644 index 0000000..5e4c881 --- /dev/null +++ b/src/features/auth/hooks/useLogin.ts @@ -0,0 +1,38 @@ +import { useState } from 'react'; +import { router } from 'expo-router'; +import { authService } from '@/features/auth/services/authService'; + +export function useLogin() { + const [email, setEmail] = useState(''); + const [password, setPassword] = useState(''); + const [isSubmitting, setIsSubmitting] = useState(false); + const [error, setError] = useState(null); + + const submit = async () => { + try { + setError(null); + setIsSubmitting(true); + + await authService.login({ + email: email.trim(), + password, + }); + + router.replace('/(protected)/home'); + } catch (err: any) { + setError(err?.message ?? 'No se pudo iniciar sesión'); + } finally { + setIsSubmitting(false); + } + }; + + return { + email, + password, + isSubmitting, + error, + setEmail, + setPassword, + submit, + }; +} -- cgit v1.2.3-54-g00ecf