feat: add role-based authentication support and update UI toggle label to Agent
This commit is contained in:
@@ -38,11 +38,16 @@ class AuthRepository {
|
||||
Future<Map<String, dynamic>> login({
|
||||
required String email,
|
||||
required String password,
|
||||
String? loginRole,
|
||||
}) async {
|
||||
try {
|
||||
final response = await _dio.post(
|
||||
ApiConstants.authLogin,
|
||||
data: {'email': email, 'password': password},
|
||||
data: {
|
||||
'email': email,
|
||||
'password': password,
|
||||
if (loginRole != null) 'loginRole': loginRole,
|
||||
},
|
||||
);
|
||||
|
||||
final data = response.data['data'] as Map<String, dynamic>;
|
||||
|
||||
@@ -135,6 +135,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
Future<void> login({
|
||||
required String email,
|
||||
required String password,
|
||||
String? loginRole,
|
||||
}) async {
|
||||
state = state.copyWith(
|
||||
status: AuthStatus.loading,
|
||||
@@ -146,6 +147,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
||||
final result = await _repository.login(
|
||||
email: email,
|
||||
password: password,
|
||||
loginRole: loginRole,
|
||||
);
|
||||
|
||||
if (result['requiresTwoFactor'] == true) {
|
||||
|
||||
@@ -53,6 +53,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
||||
ref.read(authProvider.notifier).login(
|
||||
email: _emailController.text.trim(),
|
||||
password: _passwordController.text,
|
||||
loginRole: _selectedRole,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ class RoleToggle extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
_buildToggleButton('User', 'USER'),
|
||||
_buildToggleButton('Admin', 'AGENT'),
|
||||
_buildToggleButton('Agent', 'AGENT'),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user