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/app/(auth)/_layout.tsx | 27 ++++++++++++ src/app/(auth)/login.tsx | 80 +++++++++++++++++++++++++++++++++ src/app/(auth)/register.tsx | 97 +++++++++++++++++++++++++++++++++++++++++ src/app/(auth)/welcome.tsx | 58 ++++++++++++++++++++++++ src/app/(protected)/_layout.tsx | 27 ++++++++++++ src/app/(protected)/home.tsx | 50 +++++++++++++++++++++ src/app/_layout.tsx | 62 +++----------------------- src/app/index.tsx | 54 +++++++++-------------- 8 files changed, 367 insertions(+), 88 deletions(-) (limited to 'src/app') 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 ( + + + + ); + } + + if (user) { + return ; + } + + return ; +} 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 ( + + Iniciar sesión + + + + + + {error ? {error} : null} + + + + {isSubmitting ? 'Entrando...' : 'Entrar'} + + + + + ¿No tienes cuenta? Regístrate + + + ); +} + +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 ( + + Registrarse + + + + + + + + {error ? {error} : null} + + + + {isSubmitting ? 'Registrando...' : 'Crear cuenta'} + + + + + ¿Ya tienes cuenta? Inicia sesión + + + ); +} + +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 ( + + App Oficina + Reserva de espacios de trabajo + + + + Iniciar sesión + + + + + + Registrarse + + + + ); +} + +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', + }, +}); diff --git a/src/app/(protected)/_layout.tsx b/src/app/(protected)/_layout.tsx index e69de29..ffd3d5d 100644 --- a/src/app/(protected)/_layout.tsx +++ b/src/app/(protected)/_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 ProtectedLayout() { + const { user, loading } = useAuthSession(); + + if (loading) { + return ( + + + + ); + } + + if (!user) { + return ; + } + + return ; +} diff --git a/src/app/(protected)/home.tsx b/src/app/(protected)/home.tsx index e69de29..76a5bda 100644 --- a/src/app/(protected)/home.tsx +++ b/src/app/(protected)/home.tsx @@ -0,0 +1,50 @@ +import { Pressable, StyleSheet, Text, View } from 'react-native'; +import { useAuthSession } from '@/providers/AuthProvider'; + +export default function HomeScreen() { + const { user, logout } = useAuthSession(); + + return ( + + Inicio + + Bienvenido{user?.displayName ? `, ${user.displayName}` : ''} + + {user?.email} + + + Cerrar sesión + + + ); +} + +const styles = StyleSheet.create({ + container: { + flex: 1, + justifyContent: 'center', + padding: 24, + gap: 12, + }, + title: { + fontSize: 28, + fontWeight: '700', + }, + subtitle: { + fontSize: 18, + }, + email: { + color: '#555', + marginBottom: 20, + }, + button: { + backgroundColor: '#c62828', + paddingVertical: 14, + borderRadius: 10, + alignItems: 'center', + }, + buttonText: { + color: '#fff', + fontWeight: '600', + }, +}); diff --git a/src/app/_layout.tsx b/src/app/_layout.tsx index e2eb936..710f3f2 100644 --- a/src/app/_layout.tsx +++ b/src/app/_layout.tsx @@ -1,58 +1,10 @@ -import { Slot, Stack } from "expo-router"; -import React, { Suspense } from 'react' -import AppContextProvider from "../context/AppContextProvider"; -import { ActivityIndicator, Text, View } from "react-native"; -import { openDatabaseSync, SQLiteProvider } from "expo-sqlite"; -import { drizzle } from "drizzle-orm/expo-sqlite"; -import { sql } from 'drizzle-orm'; -import { migrate, useMigrations } from "drizzle-orm/expo-sqlite/migrator"; -import migrations from "../../drizzle/migrations"; -type Props = {} -export const DATABASE_NAME = 'prueba3Drizzle'; -const sleep = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)); -function LoadingScreen() { +import { Stack } from 'expo-router'; +import { AppProviders } from '@/providers/AppProviders'; + +export default function RootLayout() { return ( - - - Cargando la app... - + + + ); } -const RootLayout = (props: Props) => { - return ( - - }> - { - try { - console.log("Simulando carga lenta..."); - await sleep(2000); // 2 segundos retraso - const db = drizzle(database); - await migrate(db, migrations); - console.log("Migration success"); - - // Activa FK aquí (después de migraciones) - await db.run(sql`PRAGMA foreign_keys = ON`); - console.log("Foreign keys enabled"); - - } catch (error) { - console.error("Migration error", error); - } - }} - > - - - - - - - ) -} - -export default RootLayout; \ No newline at end of file diff --git a/src/app/index.tsx b/src/app/index.tsx index cf5f7c1..eacde3c 100644 --- a/src/app/index.tsx +++ b/src/app/index.tsx @@ -1,39 +1,27 @@ -import { router } from "expo-router"; -import { Button, Text, View } from "react-native"; -import { SafeAreaView } from "react-native-safe-area-context"; +import { Redirect } from 'expo-router'; +import { ActivityIndicator, View } from 'react-native'; +import { useAuthSession } from '@/providers/AuthProvider'; -export default function Index() { +export default function IndexPage() { + const { user, loading } = useAuthSession(); - - function navegarGuardarPersona(){ - console.log("ir a pantalla") - router.push({ - pathname: "/GuardarPersona", - //params: - }) + if (loading) { + return ( + + + + ); } + if (user) { + return ; + } - function navegarGuardarProducto(){ - console.log("ir a pantalla") - router.push({ - pathname: "/GuardarProducto", - //params: - }) - } - return ( - - -