Manter sessão iniciada

This commit is contained in:
2026-05-10 15:36:51 +01:00
parent 85157b8673
commit 0f382e970b
2 changed files with 41 additions and 30 deletions

View File

@@ -18,21 +18,6 @@ migration:
- platform: android - platform: android
create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694 create_revision: 00b0c91f06209d9e4a41f71b7a512d6eb3b9c694
base_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 # User provided section

View File

@@ -24,35 +24,55 @@ class _SplashPageState extends State<SplashPage> {
try { try {
print('DEBUG: Checking authentication state...'); print('DEBUG: Checking authentication state...');
// Always show splash for full 3 seconds for complete animation // Check if user is currently authenticated FIRST (before any delay)
await Future.delayed(const Duration(seconds: 3));
// Check if user is currently authenticated
final currentUser = AuthService.currentUser; final currentUser = AuthService.currentUser;
if (currentUser != null) { if (currentUser != null) {
print('DEBUG: User already authenticated: ${currentUser.email}'); 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 // Reload user data to get latest information from Firebase
await currentUser.reload(); await currentUser.reload();
// Get the updated user // Get user role from Firestore
final updatedUser = AuthService.currentUser; final userRole = await AuthService.getUserRole(currentUser.uid);
print( print('DEBUG: User role: $userRole');
'DEBUG: User displayName after reload: ${updatedUser?.displayName}',
);
// Update session with current user if needed // Update session with current user if needed
await SessionService.updateSessionWithCurrentUser(); 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) { if (mounted) {
if (userRole == 'teacher') {
print('DEBUG: Navigating to teacher dashboard');
context.go('/teacher-dashboard');
} else {
print('DEBUG: Navigating to student dashboard'); print('DEBUG: Navigating to student dashboard');
context.go('/student-dashboard'); context.go('/student-dashboard');
} }
}
return; return;
} }
@@ -62,6 +82,9 @@ class _SplashPageState extends State<SplashPage> {
if (sessionData['shouldAutoLogin'] == true) { if (sessionData['shouldAutoLogin'] == true) {
print('DEBUG: Auto-login available for: ${sessionData['email']}'); 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) { if (mounted) {
// Navigate to login page with pre-filled data // Navigate to login page with pre-filled data
print('DEBUG: Navigating to login for auto-login'); print('DEBUG: Navigating to login for auto-login');
@@ -70,6 +93,9 @@ class _SplashPageState extends State<SplashPage> {
} else { } else {
print('DEBUG: No auto-login available, going to role selection'); 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) { if (mounted) {
context.go('/role-selection'); context.go('/role-selection');
} }