Manter sessão iniciada
This commit is contained in:
15
.metadata
15
.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
|
||||
|
||||
|
||||
@@ -24,35 +24,55 @@ class _SplashPageState extends State<SplashPage> {
|
||||
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) {
|
||||
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<SplashPage> {
|
||||
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<SplashPage> {
|
||||
} 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');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user