diff --git a/.metadata b/.metadata index 79dc3aa..fc44c8e 100644 --- a/.metadata +++ b/.metadata @@ -18,21 +18,6 @@ migration: - platform: android create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - - platform: ios - create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - - platform: linux - create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - - platform: macos - create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - - platform: web - create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - - platform: windows - create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 - base_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 # User provided section diff --git a/lib/features/splash/presentation/pages/splash_page.dart b/lib/features/splash/presentation/pages/splash_page.dart index 3683894..fab8204 100644 --- a/lib/features/splash/presentation/pages/splash_page.dart +++ b/lib/features/splash/presentation/pages/splash_page.dart @@ -24,34 +24,54 @@ class _SplashPageState extends State { try { print('DEBUG: Checking authentication state...'); - // Always show splash for full 3 seconds for complete animation - await Future.delayed(const Duration(seconds: 3)); - - // Check if user is currently authenticated + // Check if user is currently authenticated FIRST (before any delay) final currentUser = AuthService.currentUser; if (currentUser != null) { print('DEBUG: User already authenticated: ${currentUser.email}'); - print( - 'DEBUG: User displayName before reload: ${currentUser.displayName}', - ); + + // Check if remember me is enabled + final sessionData = await SessionService.getCurrentSession(); + final rememberMe = sessionData['rememberMe'] ?? false; + + print('DEBUG: Remember me status: $rememberMe'); + + // If user is authenticated but remember me is false, sign them out + if (!rememberMe) { + print('DEBUG: Remember me is false, signing out user'); + await AuthService.signOut(); + + // Show splash for full 3 seconds + await Future.delayed(const Duration(seconds: 3)); + + if (mounted) { + context.go('/role-selection'); + } + return; + } // Reload user data to get latest information from Firebase await currentUser.reload(); - // Get the updated user - final updatedUser = AuthService.currentUser; - print( - 'DEBUG: User displayName after reload: ${updatedUser?.displayName}', - ); + // Get user role from Firestore + final userRole = await AuthService.getUserRole(currentUser.uid); + print('DEBUG: User role: $userRole'); // Update session with current user if needed await SessionService.updateSessionWithCurrentUser(); - // Navigate to dashboard + // Minimal splash delay for authenticated users (just for smooth transition) + await Future.delayed(const Duration(milliseconds: 1500)); + + // Navigate to appropriate dashboard based on role if (mounted) { - print('DEBUG: Navigating to student dashboard'); - context.go('/student-dashboard'); + if (userRole == 'teacher') { + print('DEBUG: Navigating to teacher dashboard'); + context.go('/teacher-dashboard'); + } else { + print('DEBUG: Navigating to student dashboard'); + context.go('/student-dashboard'); + } } return; } @@ -62,6 +82,9 @@ class _SplashPageState extends State { if (sessionData['shouldAutoLogin'] == true) { print('DEBUG: Auto-login available for: ${sessionData['email']}'); + // Show splash for full 3 seconds for unauthenticated users with saved session + await Future.delayed(const Duration(seconds: 3)); + if (mounted) { // Navigate to login page with pre-filled data print('DEBUG: Navigating to login for auto-login'); @@ -70,6 +93,9 @@ class _SplashPageState extends State { } else { print('DEBUG: No auto-login available, going to role selection'); + // Show splash for full 3 seconds for new users + await Future.delayed(const Duration(seconds: 3)); + if (mounted) { context.go('/role-selection'); }