blob: 5e4c881a78454f4fe5ab9c7af047548eef14cdbb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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<string | null>(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,
};
}
|