reports page implementation

This commit is contained in:
2026-02-18 15:10:01 +05:30
parent fe87291651
commit d589c9bca2
51 changed files with 5325 additions and 11 deletions

View File

@@ -215,14 +215,57 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
staffRecord = staffResponse.data.staffs.first;
}
final String email = user?.email ?? '';
return _setSession(firebaseUser.uid, user, staffRecord);
}
@override
Future<void> restoreSession() async {
final User? firebaseUser = await _service.auth.authStateChanges().first;
if (firebaseUser == null) {
return;
}
// Reuse the same logic as verifyOtp to fetch user/staff and set session
// We can't reuse verifyOtp directly because it requires verificationId/smsCode
// So we fetch the data manually here.
final QueryResult<GetUserByIdData, GetUserByIdVariables> response =
await _service.run(
() => _service.connector.getUserById(id: firebaseUser.uid).execute(),
requiresAuthentication: false,
);
final GetUserByIdUser? user = response.data.user;
if (user == null) {
// User authenticated in Firebase but not in our DB?
// Should likely sign out or handle gracefully.
await _service.auth.signOut();
return;
}
final QueryResult<GetStaffByUserIdData, GetStaffByUserIdVariables>
staffResponse = await _service.run(
() => _service.connector.getStaffByUserId(userId: firebaseUser.uid).execute(),
requiresAuthentication: false,
);
final GetStaffByUserIdStaffs? staffRecord =
staffResponse.data.staffs.firstOrNull;
_setSession(firebaseUser.uid, user, staffRecord);
}
domain.User _setSession(
String uid,
GetUserByIdUser? user,
GetStaffByUserIdStaffs? staffRecord,
) {
//TO-DO: create(registration) user and staff account
//TO-DO: save user data locally
final domain.User domainUser = domain.User(
id: firebaseUser.uid,
email: email,
phone: firebaseUser.phoneNumber,
id: uid,
email: user?.email ?? '',
phone: user?.phone, // Use user.phone locally if needed, but domain.User expects it
role: user?.role.stringValue ?? 'USER',
);
final domain.Staff? domainStaff = staffRecord == null

View File

@@ -20,4 +20,7 @@ abstract interface class AuthRepositoryInterface {
/// Signs out the current user.
Future<void> signOut();
/// Restores the user session if a user is already signed in.
Future<void> restoreSession();
}

View File

@@ -28,7 +28,6 @@ class StaffAuthenticationModule extends Module {
@override
void binds(Injector i) {
// Repositories
i.addLazySingleton<AuthRepositoryInterface>(AuthRepositoryImpl.new);
i.addLazySingleton<ProfileSetupRepository>(ProfileSetupRepositoryImpl.new);
i.addLazySingleton<PlaceRepository>(PlaceRepositoryImpl.new);
@@ -53,6 +52,11 @@ class StaffAuthenticationModule extends Module {
);
}
@override
void exportedBinds(Injector i) {
i.addLazySingleton<AuthRepositoryInterface>(AuthRepositoryImpl.new);
}
@override
void routes(RouteManager r) {
r.child(StaffPaths.root, child: (_) => const IntroPage());

View File

@@ -3,3 +3,4 @@ export 'src/presentation/pages/get_started_page.dart';
export 'src/presentation/pages/phone_verification_page.dart';
export 'src/presentation/pages/profile_setup_page.dart';
export 'src/staff_authentication_module.dart';
export 'src/domain/repositories/auth_repository_interface.dart';