summaryrefslogtreecommitdiffstats
path: root/src/features/auth/hooks/useRegister.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/features/auth/hooks/useRegister.ts')
-rw-r--r--src/features/auth/hooks/useRegister.ts42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/features/auth/hooks/useRegister.ts b/src/features/auth/hooks/useRegister.ts
new file mode 100644
index 0000000..7b93e92
--- /dev/null
+++ b/src/features/auth/hooks/useRegister.ts
@@ -0,0 +1,42 @@
+import { useState } from 'react';
+import { router } from 'expo-router';
+import { authService } from '@/features/auth/services/authService';
+
+export function useRegister() {
+ const [displayName, setDisplayName] = useState('');
+ 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.register({
+ displayName: displayName.trim(),
+ email: email.trim(),
+ password,
+ });
+
+ router.replace('/(protected)/home');
+ } catch (err: any) {
+ setError(err?.message ?? 'No se pudo registrar el usuario');
+ } finally {
+ setIsSubmitting(false);
+ }
+ };
+
+ return {
+ displayName,
+ email,
+ password,
+ isSubmitting,
+ error,
+ setDisplayName,
+ setEmail,
+ setPassword,
+ submit,
+ };
+}