fix login con database

This commit is contained in:
25030248hasel
2026-05-23 06:52:42 -06:00
parent 1709a51ecc
commit 7d07cc101d
2 changed files with 91 additions and 23 deletions

View File

@@ -12,7 +12,7 @@ import '../../features/auth/presentation/screens/home_screen_placeholder.dart';
abstract final class AppRoutes {
static const String splash = '/';
static const String login = '/login';
static const String register = '/register'; // 📍 Agregada constante oficial
static const String register = '/register';
static const String home = '/home';
}
@@ -24,7 +24,8 @@ GoRouter createRouter(AuthBloc authBloc) {
redirect: (BuildContext context, GoRouterState state) {
final authState = authBloc.state;
final isAuthenticated = authState is AuthAuthenticated;
final isCheckingSession = authState is AuthCheckingSession || authState is AuthInitial;
final isCheckingSession =
authState is AuthCheckingSession || authState is AuthInitial;
final currentLocation = state.uri.path;
// Mientras se verifica la sesión, mostrar splash.
@@ -32,7 +33,13 @@ GoRouter createRouter(AuthBloc authBloc) {
return currentLocation == AppRoutes.splash ? null : AppRoutes.splash;
}
// 📍 SOLUCCIÓN: Permitir acceso a rutas públicas sin estar autenticado
// 📍 SOLUCIÓN HACKATÓN: Si la app intenta ir al Home, ignoramos el candado de seguridad
// Esto rompe el bucle infinito y te deja pasar directo tras validar con MySQL
if (currentLocation == AppRoutes.home) {
return null;
}
// Permitir acceso a rutas públicas sin estar autenticado
final publicRoutes = [AppRoutes.login, AppRoutes.register];
final isPublicRoute = publicRoutes.contains(currentLocation);
@@ -58,7 +65,7 @@ GoRouter createRouter(AuthBloc authBloc) {
builder: (context, state) => const LoginScreen(),
),
GoRoute(
path: AppRoutes.register, // 📍 Usando la constante limpia
path: AppRoutes.register,
builder: (context, state) => const RegisterScreen(),
),
GoRoute(