fix(mobile): resolve client crash and shift status inconsistency

This commit is contained in:
2026-02-17 16:23:10 +05:30
parent 2ebe40a920
commit da8192418f
14 changed files with 261 additions and 5 deletions

View File

@@ -10,6 +10,7 @@ import 'src/domain/usecases/sign_in_with_social_use_case.dart';
import 'src/domain/usecases/sign_out_use_case.dart';
import 'src/domain/usecases/sign_up_with_email_use_case.dart';
import 'src/presentation/blocs/client_auth_bloc.dart';
import 'src/presentation/pages/client_intro_page.dart';
import 'src/presentation/pages/client_get_started_page.dart';
import 'src/presentation/pages/client_sign_in_page.dart';
import 'src/presentation/pages/client_sign_up_page.dart';
@@ -54,7 +55,8 @@ class ClientAuthenticationModule extends Module {
@override
void routes(RouteManager r) {
r.child(ClientPaths.root, child: (_) => const ClientGetStartedPage());
r.child(ClientPaths.root, child: (_) => const ClientIntroPage());
r.child(ClientPaths.getStarted, child: (_) => const ClientGetStartedPage());
r.child(ClientPaths.signIn, child: (_) => const ClientSignInPage());
r.child(ClientPaths.signUp, child: (_) => const ClientSignUpPage());
}

View File

@@ -414,4 +414,26 @@ 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;
}
}
}

View File

@@ -34,4 +34,7 @@ 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();
}

View File

@@ -0,0 +1,63 @@
import 'dart:async';
import 'package:client_authentication/src/domain/repositories/auth_repository_interface.dart';
import 'package:flutter/material.dart';
import 'package:flutter_modular/flutter_modular.dart';
import 'package:krow_core/core.dart';
class ClientIntroPage extends StatefulWidget {
const ClientIntroPage({super.key});
@override
State<ClientIntroPage> createState() => _ClientIntroPageState();
}
class _ClientIntroPageState extends State<ClientIntroPage> {
@override
void initState() {
super.initState();
_checkSession();
}
Future<void> _checkSession() async {
// Check session immediately without artificial delay
if (!mounted) return;
try {
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');
},
);
if (mounted) {
if (user != null) {
Modular.to.navigate(ClientPaths.home);
} else {
Modular.to.navigate(ClientPaths.getStarted);
}
}
} catch (e) {
debugPrint('ClientIntroPage: Session check error: $e');
if (mounted) {
Modular.to.navigate(ClientPaths.getStarted);
}
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Theme.of(context).colorScheme.surface,
body: Center(
child: Image.asset(
'assets/logo-blue.png',
package: 'design_system',
width: 120,
),
),
);
}
}