This commit is contained in:
2026-04-28 11:05:03 +02:00
parent c49964e5c5
commit f86b52e236
3 changed files with 31 additions and 7 deletions

View File

@@ -39,8 +39,18 @@ class SessionCubit extends Cubit<SessionState> {
}
try {
// 1. CHI È QUESTO UTENTE? (Vediamo se ha un profilo staff, che sia Invitato o Admin)
final staff = await _repository.getStaffMemberByUserId(user.id);
// 1. Controllo Azienda
final company = await _repository.getCompanyByOwnerId(user.id);
CompanyModel? company;
if (staff != null) {
// L'utente esiste già nel sistema! Carichiamo l'azienda per cui lavora
company = await _repository.getCompanyById(staff.companyId);
} else {
// L'utente non ha profilo. Probabilmente è l'Admin che ha appena
// fatto Sign Up e sta iniziando l'Onboarding
company = await _repository.getCompanyByOwnerId(user.id);
}
if (company == null) {
return emit(
state.copyWith(
@@ -69,7 +79,6 @@ class SessionCubit extends Cubit<SessionState> {
}
// 3. Controllo Staff (Paziente Zero)
final staff = await _repository.getStaffMemberByUserId(user.id);
if (staff == null) {
return emit(
state.copyWith(