diff options
| author | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-03-30 14:59:30 +0100 |
|---|---|---|
| committer | Alberto Duarte Delgado <alberto@albertoduarte.com> | 2026-03-30 14:59:30 +0100 |
| commit | 6aede83b39f1050b7528b243278a85e5623856be (patch) | |
| tree | db0f2c89b18de3837f1bdf081409b09f9a763d5b /src/app/(auth) | |
| parent | 83fd8f35b080e364e667697c12d4ace7f06450df (diff) | |
Integracion Firebase
Diffstat (limited to 'src/app/(auth)')
| -rw-r--r-- | src/app/(auth)/_layout.tsx | 27 | ||||
| -rw-r--r-- | src/app/(auth)/login.tsx | 80 | ||||
| -rw-r--r-- | src/app/(auth)/register.tsx | 97 | ||||
| -rw-r--r-- | src/app/(auth)/welcome.tsx | 58 |
4 files changed, 262 insertions, 0 deletions
diff --git a/src/app/(auth)/_layout.tsx b/src/app/(auth)/_layout.tsx index e69de29..1fa69af 100644 --- a/src/app/(auth)/_layout.tsx +++ b/src/app/(auth)/_layout.tsx @@ -0,0 +1,27 @@ +import { Stack, Redirect } from 'expo-router'; +import { useAuthSession } from '@/providers/AuthProvider'; +import { ActivityIndicator, View } from 'react-native'; + +export default function AuthLayout() { + const { user, loading } = useAuthSession(); + + if (loading) { + return ( + <View + style={{ + flex: 1, + alignItems: 'center', + justifyContent: 'center', + }} + > + <ActivityIndicator size="large" /> + </View> + ); + } + + if (user) { + return <Redirect href="/(protected)/home" />; + } + + return <Stack screenOptions={{ headerShown: false }} />; +} diff --git a/src/app/(auth)/login.tsx b/src/app/(auth)/login.tsx index e69de29..5664bbf 100644 --- a/src/app/(auth)/login.tsx +++ b/src/app/(auth)/login.tsx @@ -0,0 +1,80 @@ +import { Link } from 'expo-router'; +import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; +import { useLogin } from '@/features/auth/hooks/useLogin'; + +export default function LoginScreen() { + const { email, password, setEmail, setPassword, submit, isSubmitting, error } = useLogin(); + + return ( + <View style={styles.container}> + <Text style={styles.title}>Iniciar sesión</Text> + + <TextInput + style={styles.input} + placeholder="Correo electrónico" + autoCapitalize="none" + keyboardType="email-address" + value={email} + onChangeText={setEmail} + /> + + <TextInput + style={styles.input} + placeholder="Contraseña" + secureTextEntry + value={password} + onChangeText={setPassword} + /> + + {error ? <Text style={styles.error}>{error}</Text> : null} + + <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> + <Text style={styles.buttonText}> + {isSubmitting ? 'Entrando...' : 'Entrar'} + </Text> + </Pressable> + + <Link href="/(auth)/register" style={styles.link}> + ¿No tienes cuenta? Regístrate + </Link> + </View> + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + padding: 24, + gap: 12, + }, + title: { + fontSize: 28, + fontWeight: '700', + marginBottom: 16, + }, + input: { + borderWidth: 1, + borderColor: '#ccc', + borderRadius: 10, + paddingHorizontal: 14, + paddingVertical: 12, + }, + button: { + backgroundColor: '#1f6feb', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + marginTop: 8, + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, + error: { + color: 'red', + }, + link: { + marginTop: 12, + }, +}); diff --git a/src/app/(auth)/register.tsx b/src/app/(auth)/register.tsx index e69de29..1a39a78 100644 --- a/src/app/(auth)/register.tsx +++ b/src/app/(auth)/register.tsx @@ -0,0 +1,97 @@ +import { Link } from 'expo-router'; +import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native'; +import { useRegister } from '@/features/auth/hooks/useRegister'; + +export default function RegisterScreen() { + const { + displayName, + email, + password, + setDisplayName, + setEmail, + setPassword, + submit, + isSubmitting, + error, + } = useRegister(); + + return ( + <View style={styles.container}> + <Text style={styles.title}>Registrarse</Text> + + <TextInput + style={styles.input} + placeholder="Nombre" + value={displayName} + onChangeText={setDisplayName} + /> + + <TextInput + style={styles.input} + placeholder="Correo electrónico" + autoCapitalize="none" + keyboardType="email-address" + value={email} + onChangeText={setEmail} + /> + + <TextInput + style={styles.input} + placeholder="Contraseña" + secureTextEntry + value={password} + onChangeText={setPassword} + /> + + {error ? <Text style={styles.error}>{error}</Text> : null} + + <Pressable style={styles.button} onPress={submit} disabled={isSubmitting}> + <Text style={styles.buttonText}> + {isSubmitting ? 'Registrando...' : 'Crear cuenta'} + </Text> + </Pressable> + + <Link href="/(auth)/login" style={styles.link}> + ¿Ya tienes cuenta? Inicia sesión + </Link> + </View> + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + padding: 24, + gap: 12, + }, + title: { + fontSize: 28, + fontWeight: '700', + marginBottom: 16, + }, + input: { + borderWidth: 1, + borderColor: '#ccc', + borderRadius: 10, + paddingHorizontal: 14, + paddingVertical: 12, + }, + button: { + backgroundColor: '#1f6feb', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + marginTop: 8, + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, + error: { + color: 'red', + }, + link: { + marginTop: 12, + }, +}); diff --git a/src/app/(auth)/welcome.tsx b/src/app/(auth)/welcome.tsx index e69de29..9b00154 100644 --- a/src/app/(auth)/welcome.tsx +++ b/src/app/(auth)/welcome.tsx @@ -0,0 +1,58 @@ +import { Link } from 'expo-router'; +import { StyleSheet, Text, View, Pressable } from 'react-native'; + +export default function WelcomeScreen() { + return ( + <View style={styles.container}> + <Text style={styles.title}>App Oficina</Text> + <Text style={styles.subtitle}>Reserva de espacios de trabajo</Text> + + <Link href="/(auth)/login" asChild> + <Pressable style={styles.button}> + <Text style={styles.buttonText}>Iniciar sesión</Text> + </Pressable> + </Link> + + <Link href="/(auth)/register" asChild> + <Pressable style={styles.buttonSecondary}> + <Text style={styles.buttonText}>Registrarse</Text> + </Pressable> + </Link> + </View> + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + padding: 24, + gap: 16, + }, + title: { + fontSize: 32, + fontWeight: '700', + textAlign: 'center', + }, + subtitle: { + fontSize: 16, + textAlign: 'center', + marginBottom: 24, + }, + button: { + backgroundColor: '#1f6feb', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + }, + buttonSecondary: { + backgroundColor: '#444', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, +}); |