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({
|
Future<Map<String, dynamic>> login({
|
||||||
required String email,
|
required String email,
|
||||||
required String password,
|
required String password,
|
||||||
|
String? loginRole,
|
||||||
}) async {
|
}) async {
|
||||||
try {
|
try {
|
||||||
final response = await _dio.post(
|
final response = await _dio.post(
|
||||||
ApiConstants.authLogin,
|
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>;
|
final data = response.data['data'] as Map<String, dynamic>;
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
|||||||
Future<void> login({
|
Future<void> login({
|
||||||
required String email,
|
required String email,
|
||||||
required String password,
|
required String password,
|
||||||
|
String? loginRole,
|
||||||
}) async {
|
}) async {
|
||||||
state = state.copyWith(
|
state = state.copyWith(
|
||||||
status: AuthStatus.loading,
|
status: AuthStatus.loading,
|
||||||
@@ -146,6 +147,7 @@ class AuthNotifier extends StateNotifier<AuthState> {
|
|||||||
final result = await _repository.login(
|
final result = await _repository.login(
|
||||||
email: email,
|
email: email,
|
||||||
password: password,
|
password: password,
|
||||||
|
loginRole: loginRole,
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result['requiresTwoFactor'] == true) {
|
if (result['requiresTwoFactor'] == true) {
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
|
|||||||
ref.read(authProvider.notifier).login(
|
ref.read(authProvider.notifier).login(
|
||||||
email: _emailController.text.trim(),
|
email: _emailController.text.trim(),
|
||||||
password: _passwordController.text,
|
password: _passwordController.text,
|
||||||
|
loginRole: _selectedRole,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class RoleToggle extends StatelessWidget {
|
|||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
_buildToggleButton('User', 'USER'),
|
_buildToggleButton('User', 'USER'),
|
||||||
_buildToggleButton('Admin', 'AGENT'),
|
_buildToggleButton('Agent', 'AGENT'),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user