fix
This commit is contained in:
@@ -39,8 +39,18 @@ class SessionCubit extends Cubit<SessionState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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
|
// 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) {
|
if (company == null) {
|
||||||
return emit(
|
return emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
@@ -69,7 +79,6 @@ class SessionCubit extends Cubit<SessionState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3. Controllo Staff (Paziente Zero)
|
// 3. Controllo Staff (Paziente Zero)
|
||||||
final staff = await _repository.getStaffMemberByUserId(user.id);
|
|
||||||
if (staff == null) {
|
if (staff == null) {
|
||||||
return emit(
|
return emit(
|
||||||
state.copyWith(
|
state.copyWith(
|
||||||
|
|||||||
@@ -28,6 +28,21 @@ class CoreRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<CompanyModel?> getCompanyById(String companyId) async {
|
||||||
|
try {
|
||||||
|
final response = await _supabase
|
||||||
|
.from('company')
|
||||||
|
.select()
|
||||||
|
.eq('id', companyId)
|
||||||
|
.maybeSingle();
|
||||||
|
if (response == null) return null;
|
||||||
|
return CompanyModel.fromMap(response);
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint('Errore recupero azienda per ID: $e');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<List<StoreModel>> getStoresByCompanyId(String companyId) async {
|
Future<List<StoreModel>> getStoresByCompanyId(String companyId) async {
|
||||||
try {
|
try {
|
||||||
final response = await _supabase
|
final response = await _supabase
|
||||||
|
|||||||
Reference in New Issue
Block a user