validation when the user is not a businnes user
This commit is contained in:
@@ -34,12 +34,29 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
throw Exception('Sign-in failed, no Firebase user received.');
|
throw Exception('Sign-in failed, no Firebase user received.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return _getUserProfile(
|
final response = await _dataConnect.getUserById(
|
||||||
firebaseUserId: firebaseUser.uid,
|
id: firebaseUser.uid,
|
||||||
fallbackEmail: firebaseUser.email ?? email,
|
).execute();
|
||||||
);
|
final user = response.data?.user;
|
||||||
|
if (user == null) {
|
||||||
|
await _firebaseAuth.signOut();
|
||||||
|
throw Exception('Authenticated user profile not found in database.');
|
||||||
|
}
|
||||||
|
if (user.userRole != 'BUSINESS') {
|
||||||
|
await _firebaseAuth.signOut();
|
||||||
|
throw Exception('User is not authorized for this app.');
|
||||||
|
}
|
||||||
|
|
||||||
//TO-DO: validate that user is business role and has business account
|
final resolvedEmail = user.email ?? firebaseUser.email ?? email;
|
||||||
|
if (resolvedEmail.isEmpty) {
|
||||||
|
throw Exception('User email is missing in profile data.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return domain.User(
|
||||||
|
id: user.id,
|
||||||
|
email: resolvedEmail,
|
||||||
|
role: user.role.stringValue,
|
||||||
|
);
|
||||||
|
|
||||||
} on firebase.FirebaseAuthException catch (e) {
|
} on firebase.FirebaseAuthException catch (e) {
|
||||||
if (e.code == 'invalid-credential' || e.code == 'wrong-password') {
|
if (e.code == 'invalid-credential' || e.code == 'wrong-password') {
|
||||||
@@ -47,6 +64,8 @@ class AuthRepositoryImpl implements AuthRepositoryInterface {
|
|||||||
} else {
|
} else {
|
||||||
throw Exception('Authentication error: ${e.message}');
|
throw Exception('Authentication error: ${e.message}');
|
||||||
}
|
}
|
||||||
|
} on Exception catch (e) {
|
||||||
|
throw e;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
throw Exception('Failed to sign in and fetch user data: ${e.toString()}');
|
throw Exception('Failed to sign in and fetch user data: ${e.toString()}');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user