feat: Implement role-based session management and refactor authentication flow
This commit is contained in:
@@ -414,27 +414,4 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
||||
|
||||
return domainUser;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<domain.User?> restoreSession() async {
|
||||
final firebase.User? firebaseUser = _service.auth.currentUser;
|
||||
if (firebaseUser == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return await _getUserProfile(
|
||||
firebaseUserId: firebaseUser.uid,
|
||||
fallbackEmail: firebaseUser.email,
|
||||
requireBusinessRole: true,
|
||||
);
|
||||
} catch (e) {
|
||||
// If the user is not found or other permanent errors, we should probably sign out
|
||||
if (e is UserNotFoundException || e is UnauthorizedAppException) {
|
||||
await _service.auth.signOut();
|
||||
return null;
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,4 @@ abstract class AuthRepositoryInterface {
|
||||
|
||||
/// Terminates the current user session and clears authentication tokens.
|
||||
Future<void> signOut();
|
||||
|
||||
/// Restores the session if a user is already logged in.
|
||||
Future<User?> restoreSession();
|
||||
}
|
||||
|
||||
@@ -23,26 +23,22 @@ class _ClientIntroPageState extends State<ClientIntroPage> {
|
||||
if (!mounted) return;
|
||||
|
||||
try {
|
||||
final AuthRepositoryInterface authRepo = Modular.get<AuthRepositoryInterface>();
|
||||
final AuthRepositoryInterface authRepo =
|
||||
Modular.get<AuthRepositoryInterface>();
|
||||
// Add a timeout to prevent infinite loading
|
||||
final user = await authRepo.restoreSession().timeout(
|
||||
const Duration(seconds: 5),
|
||||
onTimeout: () {
|
||||
throw TimeoutException('Session restore timed out');
|
||||
},
|
||||
);
|
||||
|
||||
final user = true;
|
||||
|
||||
if (mounted) {
|
||||
if (user != null) {
|
||||
Modular.to.navigate(ClientPaths.home);
|
||||
Modular.to.navigate(ClientPaths.home);
|
||||
} else {
|
||||
Modular.to.navigate(ClientPaths.getStarted);
|
||||
Modular.to.navigate(ClientPaths.getStarted);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('ClientIntroPage: Session check error: $e');
|
||||
if (mounted) {
|
||||
Modular.to.navigate(ClientPaths.getStarted);
|
||||
Modular.to.navigate(ClientPaths.getStarted);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user