rd-android-app/lib/screens/authentication/controller/auth_service.dart
2024-09-20 15:50:11 +05:30

57 lines
1.5 KiB
Dart

import 'package:cheminova/utils/common_api_service.dart';
import 'package:cheminova/utils/show_snackbar.dart';
class AuthService {
Future<Map<String, dynamic>?> login(Map<String, dynamic> data) async {
try {
final response = await commonApiService<Map<String, dynamic>>(
url: '/api/rd-login',
method: 'POST',
body: data,
fromJson: (json) => json, // Simply return the JSON map as is
);
return response;
} catch (e) {
showSnackbar(e.toString());
}
return null;
}
Future<Map<String, dynamic>?> forgotPassword(Map<String, dynamic> data) async {
try {
final response = await commonApiService<Map<String, dynamic>>(
url: '/api/forgot-password',
method: 'POST',
body: data,
fromJson: (json) => json, // Simply return the JSON map as is
);
return response;
} catch (e) {
showSnackbar(e.toString());
}
return null;
}
Future<Map<String, dynamic>?> changePassword(Map<String, dynamic> data, {required String token}) async {
try {
final response = await commonApiService<Map<String, dynamic>>(
url: '/api/rd-password/update',
method: 'PUT',
body: data,
fromJson: (json) => json, // Simply return the JSON map as is
additionalHeaders: { // Pass the token here
'Authorization': 'Bearer $token',
},
);
return response;
} catch (e) {
showSnackbar(e.toString());
}
return null;
}
}