@@ -40,9 +40,26 @@ 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
|
||||
StaffMemberModel? staff = await _repository.getStaffMemberByUserId(
|
||||
user.id,
|
||||
);
|
||||
CompanyModel? company;
|
||||
if (staff != null) {
|
||||
// --- LA MAGIA DEL SENSORE ---
|
||||
if (staff.hasJoined == false) {
|
||||
// È la primissima volta che entra! Aggiorniamo il DB.
|
||||
await _repository.updateStaffMember(staff.id!, {'has_joined': true});
|
||||
// Aggiorniamo anche il nostro modello in memoria per questa sessione
|
||||
staff = staff.copyWith(hasJoined: true);
|
||||
}
|
||||
|
||||
company = await _repository.getCompanyById(staff.companyId);
|
||||
} else {
|
||||
// È l'Admin in onboarding
|
||||
company = await _repository.getCompanyByOwnerId(user.id);
|
||||
}
|
||||
// 1. Controllo Azienda
|
||||
|
||||
if (staff != null) {
|
||||
// L'utente esiste già nel sistema! Carichiamo l'azienda per cui lavora
|
||||
company = await _repository.getCompanyById(staff.companyId);
|
||||
|
||||
2
lib/core/data/constants.dart
Normal file
2
lib/core/data/constants.dart
Normal file
@@ -0,0 +1,2 @@
|
||||
const String resetPasswordUrl =
|
||||
'https://flux-web-invite.marco-6ba.workers.dev/';
|
||||
@@ -131,4 +131,11 @@ class CoreRepository {
|
||||
'store_id': storeId,
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> updateStaffMember(
|
||||
String staffId,
|
||||
Map<String, dynamic> data,
|
||||
) async {
|
||||
await _supabase.from('staff_member').update(data).eq('id', staffId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user