diff --git a/lib/core/networking/api/api_service.dart b/lib/core/networking/api/api_service.dart index b52be20..7aef86e 100644 --- a/lib/core/networking/api/api_service.dart +++ b/lib/core/networking/api/api_service.dart @@ -49,35 +49,44 @@ abstract class ApiService { @POST(ApiConstants.setDeviceToken) Future setDeviceToken( @Body() DeviceTokenRequestBody deviceToken, - @Header('Authorization') String? auth, ); // Logout @POST(ApiConstants.logout) - Future logout( - @Header('Authorization') String? auth, - ); + Future logout(); // Sign in @POST(ApiConstants.signIn) + @Headers({ + 'requires-token': 'false', + }) Future signin( @Body() SigninRequestBody signinRequestBody, ); // Signup @POST(ApiConstants.signUp) + @Headers({ + 'requires-token': 'false', + }) Future signup( @Body() SignupRequestBody signupRequestBody, ); // Resend Verification @POST(ApiConstants.sendVerification) + @Headers({ + 'requires-token': 'false', + }) Future resendVerification( @Queries() VerificationRequestParams verificationRequestParams, ); // Forget Password @POST(ApiConstants.forgetPassword) + @Headers({ + 'requires-token': 'false', + }) Future forgetPassword( @Body() ForgetPasswordRequestBody forgetPasswordRequestBody, ); @@ -86,15 +95,12 @@ abstract class ApiService { // Get Reminder List @GET(ApiConstants.reminderList) - Future> getReminderList( - @Header('Authorization') String? auth, - ); + Future> getReminderList(); // Make Reminder Done @PUT(ApiConstants.makeReminderDone) Future makeReminderDone( @Path('reminder_id') int reminderId, - @Header('Authorization') String? auth, ); //-------------------- Prescription --------------------// @@ -103,21 +109,18 @@ abstract class ApiService { @GET(ApiConstants.prescriptionsList1) Future> getPrescriptionsDoctors( @Queries() StateRequestBody stateRequestBody, - @Header('Authorization') String? auth, ); // Prescription @GET(ApiConstants.prescriptionsList2) Future> getPrescriptionsDrugs( @Queries() StateRequestBody stateRequestBody, - @Header('Authorization') String? auth, ); // Prescription Detail @GET(ApiConstants.specificPrescriptionInfo) Future getSpecificPrescriptionInfo( @Path('prescription_id') int prescriptionId, - @Header('Authorization') String? auth, ); // Activate Drug @@ -125,7 +128,6 @@ abstract class ApiService { Future activateDrug( @Path('prescription_id') int prescriptionId, @Query('drug_name') String drugName, - @Header('Authorization') String? auth, ); // Deactivate Drug @@ -133,21 +135,18 @@ abstract class ApiService { Future deactivateDrug( @Path('prescription_id') int prescriptionId, @Query('drug_name') String drugName, - @Header('Authorization') String? auth, ); // Activate Prescription @POST(ApiConstants.activatePrescription) Future activatePrescription( @Path('prescription_id') int prescriptionId, - @Header('Authorization') String? auth, ); // Deactivate Prescription @POST(ApiConstants.deactivatePrescription) Future deactivatePrescription( @Path('prescription_id') int prescriptionId, - @Header('Authorization') String? auth, ); //-------------------- DRUG INTERACTION --------------------// @@ -177,15 +176,12 @@ abstract class ApiService { // User Profile Data @GET(ApiConstants.userInformation) - Future getUserInformation( - @Header('Authorization') String? auth, - ); + Future getUserInformation(); // Update User Profile @PATCH(ApiConstants.updateUserInformation) Future updateUserInformation( @Body() User user, - @Header('Authorization') String? auth, ); // Update User Image @@ -196,28 +192,23 @@ abstract class ApiService { @MultiPart() Future updateUserImage( @Part() File image, - @Header('Authorization') String? auth, ); // Change Password @PATCH(ApiConstants.changePassword) Future changePassword( @Body() ChangePasswordRequestBody changePasswordRequestBody, - @Header('Authorization') String? auth, ); //-------------------- Doctor --------------------// // Get Doctors List @GET(ApiConstants.doctorsList) - Future> getDoctorList( - @Header('Authorization') String? auth, - ); + Future> getDoctorList(); @GET(ApiConstants.doctorProfile) Future getDoctorProfile( @Path('doctor_id') int doctorId, - @Header('Authorization') String? auth, ); //-------------------- Chat --------------------// @@ -228,7 +219,6 @@ abstract class ApiService { @Query('receiver_doctor_id') int receiverDoctorId, @Query('page') int page, @Query('page_size') int pageSize, - @Header('Authorization') String? auth, ); // @Put(ApiConstants.updateMessage) diff --git a/lib/core/networking/api/api_service.g.dart b/lib/core/networking/api/api_service.g.dart index b7b556e..1073758 100644 --- a/lib/core/networking/api/api_service.g.dart +++ b/lib/core/networking/api/api_service.g.dart @@ -51,14 +51,10 @@ class _ApiService implements ApiService { @override Future setDeviceToken( - DeviceTokenRequestBody deviceToken, - String? auth, - ) async { + DeviceTokenRequestBody deviceToken) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; final _data = {}; _data.addAll(deviceToken.toJson()); final _result = await _dio @@ -83,12 +79,10 @@ class _ApiService implements ApiService { } @override - Future logout(String? auth) async { + Future logout() async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; await _dio.fetch(_setStreamType(Options( method: 'POST', @@ -112,7 +106,8 @@ class _ApiService implements ApiService { Future signin(SigninRequestBody signinRequestBody) async { final _extra = {}; final queryParameters = {}; - final _headers = {}; + final _headers = {r'requires-token': 'false'}; + _headers.removeWhere((k, v) => v == null); final _data = {}; _data.addAll(signinRequestBody.toJson()); final _result = await _dio @@ -140,7 +135,8 @@ class _ApiService implements ApiService { Future signup(SignupRequestBody signupRequestBody) async { final _extra = {}; final queryParameters = {}; - final _headers = {}; + final _headers = {r'requires-token': 'false'}; + _headers.removeWhere((k, v) => v == null); final _data = {}; _data.addAll(signupRequestBody.toJson()); final _result = await _dio @@ -170,7 +166,8 @@ class _ApiService implements ApiService { final _extra = {}; final queryParameters = {}; queryParameters.addAll(verificationRequestParams.toJson()); - final _headers = {}; + final _headers = {r'requires-token': 'false'}; + _headers.removeWhere((k, v) => v == null); const Map? _data = null; final _result = await _dio.fetch>( _setStreamType(Options( @@ -198,7 +195,8 @@ class _ApiService implements ApiService { ForgetPasswordRequestBody forgetPasswordRequestBody) async { final _extra = {}; final queryParameters = {}; - final _headers = {}; + final _headers = {r'requires-token': 'false'}; + _headers.removeWhere((k, v) => v == null); final _data = {}; _data.addAll(forgetPasswordRequestBody.toJson()); final _result = await _dio @@ -223,12 +221,10 @@ class _ApiService implements ApiService { } @override - Future> getReminderList(String? auth) async { + Future> getReminderList() async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio.fetch>(_setStreamType>(Options( @@ -254,15 +250,10 @@ class _ApiService implements ApiService { } @override - Future makeReminderDone( - int reminderId, - String? auth, - ) async { + Future makeReminderDone(int reminderId) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; await _dio.fetch(_setStreamType(Options( method: 'PUT', @@ -284,15 +275,11 @@ class _ApiService implements ApiService { @override Future> getPrescriptionsDoctors( - StateRequestBody stateRequestBody, - String? auth, - ) async { + StateRequestBody stateRequestBody) async { final _extra = {}; final queryParameters = {}; queryParameters.addAll(stateRequestBody.toJson()); - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType>(Options( @@ -320,15 +307,11 @@ class _ApiService implements ApiService { @override Future> getPrescriptionsDrugs( - StateRequestBody stateRequestBody, - String? auth, - ) async { + StateRequestBody stateRequestBody) async { final _extra = {}; final queryParameters = {}; queryParameters.addAll(stateRequestBody.toJson()); - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType>(Options( @@ -356,14 +339,10 @@ class _ApiService implements ApiService { @override Future getSpecificPrescriptionInfo( - int prescriptionId, - String? auth, - ) async { + int prescriptionId) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -390,13 +369,10 @@ class _ApiService implements ApiService { Future activateDrug( int prescriptionId, String drugName, - String? auth, ) async { final _extra = {}; final queryParameters = {r'drug_name': drugName}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -423,13 +399,10 @@ class _ApiService implements ApiService { Future deactivateDrug( int prescriptionId, String drugName, - String? auth, ) async { final _extra = {}; final queryParameters = {r'drug_name': drugName}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -453,15 +426,10 @@ class _ApiService implements ApiService { } @override - Future activatePrescription( - int prescriptionId, - String? auth, - ) async { + Future activatePrescription(int prescriptionId) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -485,15 +453,10 @@ class _ApiService implements ApiService { } @override - Future deactivatePrescription( - int prescriptionId, - String? auth, - ) async { + Future deactivatePrescription(int prescriptionId) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -620,12 +583,10 @@ class _ApiService implements ApiService { } @override - Future getUserInformation(String? auth) async { + Future getUserInformation() async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio.fetch>(_setStreamType(Options( @@ -649,15 +610,10 @@ class _ApiService implements ApiService { } @override - Future updateUserInformation( - User user, - String? auth, - ) async { + Future updateUserInformation(User user) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; final _data = {}; _data.addAll(user.toJson()); final _result = @@ -682,17 +638,10 @@ class _ApiService implements ApiService { } @override - Future updateUserImage( - File image, - String? auth, - ) async { + Future updateUserImage(File image) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = { - r'Content-Type': 'application/json', - r'Authorization': auth, - }; + final _headers = {r'Content-Type': 'application/json'}; _headers.removeWhere((k, v) => v == null); final _data = FormData(); _data.files.add(MapEntry( @@ -726,14 +675,10 @@ class _ApiService implements ApiService { @override Future changePassword( - ChangePasswordRequestBody changePasswordRequestBody, - String? auth, - ) async { + ChangePasswordRequestBody changePasswordRequestBody) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; final _data = {}; _data.addAll(changePasswordRequestBody.toJson()); final _result = await _dio.fetch>( @@ -758,12 +703,10 @@ class _ApiService implements ApiService { } @override - Future> getDoctorList(String? auth) async { + Future> getDoctorList() async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio.fetch>(_setStreamType>(Options( @@ -789,15 +732,10 @@ class _ApiService implements ApiService { } @override - Future getDoctorProfile( - int doctorId, - String? auth, - ) async { + Future getDoctorProfile(int doctorId) async { final _extra = {}; final queryParameters = {}; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio .fetch>(_setStreamType(Options( @@ -826,7 +764,6 @@ class _ApiService implements ApiService { int receiverDoctorId, int page, int pageSize, - String? auth, ) async { final _extra = {}; final queryParameters = { @@ -835,9 +772,7 @@ class _ApiService implements ApiService { r'page': page, r'page_size': pageSize, }; - queryParameters.removeWhere((k, v) => v == null); - final _headers = {r'Authorization': auth}; - _headers.removeWhere((k, v) => v == null); + final _headers = {}; const Map? _data = null; final _result = await _dio.fetch>( _setStreamType(Options( diff --git a/lib/core/networking/api/app_dio_factory.dart b/lib/core/networking/api/app_dio_factory.dart index 6f70e52..d8b260c 100644 --- a/lib/core/networking/api/app_dio_factory.dart +++ b/lib/core/networking/api/app_dio_factory.dart @@ -1,6 +1,6 @@ import 'package:dio/dio.dart'; import 'package:pretty_dio_logger/pretty_dio_logger.dart'; -import 'refresh_token_interceptor.dart'; +import 'interceptors/auth_interceptor.dart'; class AppDioFactory { /// private constructor as I don't want to allow creating an instance of this class @@ -24,7 +24,7 @@ class AppDioFactory { } static void addDioInterceptor() { - dio?.interceptors.add(RefreshTokenInterceptor()); + dio?.interceptors.add(AuthInterceptor()); dio?.interceptors.add( PrettyDioLogger( diff --git a/lib/core/networking/api/refresh_token_interceptor.dart b/lib/core/networking/api/interceptors/auth_interceptor.dart similarity index 58% rename from lib/core/networking/api/refresh_token_interceptor.dart rename to lib/core/networking/api/interceptors/auth_interceptor.dart index ee77947..a9cc0d2 100644 --- a/lib/core/networking/api/refresh_token_interceptor.dart +++ b/lib/core/networking/api/interceptors/auth_interceptor.dart @@ -1,17 +1,15 @@ -import 'package:auto_route/auto_route.dart'; import 'package:dio/dio.dart'; import 'package:logger/logger.dart'; -import 'package:pharmalink/core/models/message_response.dart'; import 'package:pharmalink/core/networking/api/api_constants.dart'; import 'package:pharmalink/core/networking/api/api_error_handler.dart'; import 'package:pharmalink/core/routes/app_router.dart'; import 'package:pharmalink/core/shared_preferences/auth_prefs.dart'; -import '../../../features/access/auth/data/models/refresh_token_response.dart'; -import '../../../pharmalink_app.dart'; -import 'api_result.dart'; +import '../../../../features/access/auth/data/models/refresh_token_response.dart'; +import '../../../../pharmalink_app.dart'; +import '../api_result.dart'; -class RefreshTokenInterceptor extends Interceptor { - RefreshTokenInterceptor(); +class AuthInterceptor extends Interceptor { + AuthInterceptor(); // Instance of Dio final Dio _dio = Dio(BaseOptions(baseUrl: ApiConstants.httpsDomain)); @@ -37,9 +35,30 @@ class RefreshTokenInterceptor extends Interceptor { } // ------------------ Interceptor ------------------ // + + @override + Future onRequest( + RequestOptions options, + RequestInterceptorHandler handler, + ) async { + if (options.headers['requires-token'] == 'false') { + // if the request doesn't need token, then just continue to the next + // interceptor + options.headers.remove('requires-token'); //remove the auxiliary header + return handler.next(options); + } + + final accessToken = AuthSharedPrefs.getAccessToken(); + + options.headers + .addAll({'authorization': '${ApiConstants.tokenKey} $accessToken'}); + return handler.next(options); + } + @override void onError(DioException err, ErrorInterceptorHandler handler) async { - if (err.response?.statusCode == 401) { + if (err.type == DioExceptionType.badResponse && + err.response?.statusCode == 401) { // Attempt to refresh the token final response = await refreshToken(); @@ -48,16 +67,17 @@ class RefreshTokenInterceptor extends Interceptor { // Save the new token await AuthSharedPrefs.setAccessToken(newToken.accessToken); // Retry the request with the new token - await retry(handler, err); + handler.resolve(await _retryRequest(err.requestOptions)); }, failure: (error) async { // Refresh token failed appRouter.push(const SignRoute()); - Logger().i(appRouter.currentPath); // Clear the auth data await AuthSharedPrefs.clearAuthData(); + Logger().i(appRouter.currentPath); + // So reject the request handler.reject(err); }, @@ -67,29 +87,20 @@ class RefreshTokenInterceptor extends Interceptor { } } - Future retry(ErrorInterceptorHandler handler, DioException err) async { + Future> _retryRequest(RequestOptions requestOptions) async { // Update the token in headers - final requestOptions = err.requestOptions; requestOptions.headers['Authorization'] = AuthSharedPrefs.getAccessToken(); - try { - final response = await _dio.request( - requestOptions.path, - options: Options( - method: requestOptions.method, - headers: requestOptions.headers, - ), - data: requestOptions.data, - queryParameters: requestOptions.queryParameters, - ); - handler.resolve(response); - } catch (e) { - handler.reject( - DioException( - requestOptions: requestOptions, - error: e, - ), - ); - } + final response = await _dio.request( + requestOptions.path, + options: Options( + method: requestOptions.method, + headers: requestOptions.headers, + ), + data: requestOptions.data, + queryParameters: requestOptions.queryParameters, + ); + + return response; } } diff --git a/lib/core/notifications/firebase_notifications.dart b/lib/core/notifications/firebase_notifications.dart index d619159..e2ae87a 100644 --- a/lib/core/notifications/firebase_notifications.dart +++ b/lib/core/notifications/firebase_notifications.dart @@ -52,7 +52,6 @@ class FirebaseNotifications { _firebaseMessaging.onTokenRefresh.listen((deviceToken) { _apiService.setDeviceToken( DeviceTokenRequestBody(deviceToken: deviceToken), - AuthSharedPrefs.getAccessToken(), ); }).onError((err) { // Error getting token. diff --git a/lib/core/shared_preferences/auth_prefs.dart b/lib/core/shared_preferences/auth_prefs.dart index 1f368d2..ca3e3f5 100644 --- a/lib/core/shared_preferences/auth_prefs.dart +++ b/lib/core/shared_preferences/auth_prefs.dart @@ -2,7 +2,6 @@ import 'package:logger/logger.dart'; import 'package:pharmalink/core/di/dependency_injection.dart'; -import 'package:pharmalink/core/networking/api/api_constants.dart'; import 'package:pharmalink/core/shared_preferences/shared_preferences_service.dart'; import 'package:pharmalink/features/access/sign/data/models/signin/signin_response.dart'; @@ -32,7 +31,7 @@ abstract class AuthSharedPrefs { } static String? getAccessToken() { - return "${ApiConstants.tokenKey} ${SharedPrefsService.getString(_ACCESS_TOKEN)}"; + return SharedPrefsService.getString(_ACCESS_TOKEN); } static String? getRefreshToken() { diff --git a/lib/features/access/auth/data/repo/auth_repo.dart b/lib/features/access/auth/data/repo/auth_repo.dart index 065cd86..b0d6b22 100644 --- a/lib/features/access/auth/data/repo/auth_repo.dart +++ b/lib/features/access/auth/data/repo/auth_repo.dart @@ -22,7 +22,7 @@ class AuthRepo { Future logout() async { try { - await _apiService.logout(AuthSharedPrefs.getAccessToken()); + await _apiService.logout(); } catch (error) { getIt().e(error); } diff --git a/lib/features/access/sign/data/repo/signin_repo.dart b/lib/features/access/sign/data/repo/signin_repo.dart index 608d9d1..c2c9506 100644 --- a/lib/features/access/sign/data/repo/signin_repo.dart +++ b/lib/features/access/sign/data/repo/signin_repo.dart @@ -34,7 +34,6 @@ class SigninRepo { final deviceToken = await getIt().getDeviceToken(); final response = await _apiService.setDeviceToken( DeviceTokenRequestBody(deviceToken: deviceToken), - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); } catch (error) { diff --git a/lib/features/main/chat/data/repo/chat_repo.dart b/lib/features/main/chat/data/repo/chat_repo.dart index 815b2cc..7690e96 100644 --- a/lib/features/main/chat/data/repo/chat_repo.dart +++ b/lib/features/main/chat/data/repo/chat_repo.dart @@ -75,7 +75,6 @@ class ChatRepo { receiverId, pageNumber, pageSize, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(result); diff --git a/lib/features/main/doctors/data/repo/doctors_repo.dart b/lib/features/main/doctors/data/repo/doctors_repo.dart index 43ca904..21dfc86 100644 --- a/lib/features/main/doctors/data/repo/doctors_repo.dart +++ b/lib/features/main/doctors/data/repo/doctors_repo.dart @@ -15,7 +15,7 @@ class DoctorsRepo { Future>> getDoctorList() async { try { final response = - await _apiService.getDoctorList(AuthSharedPrefs.getAccessToken()); + await _apiService.getDoctorList(); return ApiResult.success(response); } catch (error) { getIt().e(error); @@ -27,7 +27,6 @@ class DoctorsRepo { try { final response = await _apiService.getDoctorProfile( doctorId, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); } catch (error) { diff --git a/lib/features/main/prescription/data/repo/prescription_repo.dart b/lib/features/main/prescription/data/repo/prescription_repo.dart index 867aa37..192ff56 100644 --- a/lib/features/main/prescription/data/repo/prescription_repo.dart +++ b/lib/features/main/prescription/data/repo/prescription_repo.dart @@ -20,7 +20,6 @@ class PrescriptionRepo { try { final prescription = await _apiService.getSpecificPrescriptionInfo( prescriptionId, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(prescription); } catch (error) { @@ -34,7 +33,6 @@ class PrescriptionRepo { try { final prescriptions = await _apiService.getPrescriptionsDoctors( StateRequestBody(state: drugState), - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(prescriptions); } catch (error) { @@ -48,7 +46,6 @@ class PrescriptionRepo { try { final prescriptions = await _apiService.getPrescriptionsDrugs( StateRequestBody(state: drugState), - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(prescriptions); } catch (error) { @@ -64,7 +61,6 @@ class PrescriptionRepo { try { final message = await _apiService.activatePrescription( prescriptionId, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(message); } catch (error) { @@ -80,7 +76,6 @@ class PrescriptionRepo { try { final message = await _apiService.deactivatePrescription( prescriptionId, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(message); } catch (error) { @@ -98,7 +93,6 @@ class PrescriptionRepo { final message = await _apiService.activateDrug( prescriptionId, drugName, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(message); } catch (error) { @@ -116,7 +110,6 @@ class PrescriptionRepo { final message = await _apiService.deactivateDrug( prescriptionId, drugName, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(message); } catch (error) { diff --git a/lib/features/main/profile/data/repo/profile_repo.dart b/lib/features/main/profile/data/repo/profile_repo.dart index 080ad40..af2bf30 100644 --- a/lib/features/main/profile/data/repo/profile_repo.dart +++ b/lib/features/main/profile/data/repo/profile_repo.dart @@ -14,7 +14,6 @@ class ProfileRepo { Future> getUserInformation() async { try { final user = await _apiService.getUserInformation( - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(user); } catch (error) { diff --git a/lib/features/main/reminders/data/repo/reminders_repo.dart b/lib/features/main/reminders/data/repo/reminders_repo.dart index 07517db..90cdec8 100644 --- a/lib/features/main/reminders/data/repo/reminders_repo.dart +++ b/lib/features/main/reminders/data/repo/reminders_repo.dart @@ -22,7 +22,7 @@ class RemindersRepo { Future>> getRemindersList() async { try { final reminders = - await _apiService.getReminderList(AuthSharedPrefs.getAccessToken()); + await _apiService.getReminderList(); return ApiResult.success(reminders); } catch (error) { getIt().e(error); @@ -34,7 +34,6 @@ class RemindersRepo { try { final response = await _apiService.makeReminderDone( reminderId, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); } catch (error) { diff --git a/lib/features/main/settings/change_password/data/repo/change_password_repo.dart b/lib/features/main/settings/change_password/data/repo/change_password_repo.dart index ce9909b..b847be3 100644 --- a/lib/features/main/settings/change_password/data/repo/change_password_repo.dart +++ b/lib/features/main/settings/change_password/data/repo/change_password_repo.dart @@ -15,7 +15,6 @@ class ChangePasswordRepo { try { final response = await _apiService.changePassword( changePasswordRequestBody, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); diff --git a/lib/features/main/settings/edit_profile/data/repo/edit_profile_repo.dart b/lib/features/main/settings/edit_profile/data/repo/edit_profile_repo.dart index 6d37cda..e3dbf06 100644 --- a/lib/features/main/settings/edit_profile/data/repo/edit_profile_repo.dart +++ b/lib/features/main/settings/edit_profile/data/repo/edit_profile_repo.dart @@ -17,7 +17,6 @@ class EditProfileRepo { Future> getUserInformation() async { try { final drugs = await _apiService.getUserInformation( - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(drugs); } catch (error) { @@ -30,7 +29,6 @@ class EditProfileRepo { try { final response = await _apiService.updateUserInformation( user, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); } catch (error) { @@ -43,7 +41,6 @@ class EditProfileRepo { try { final response = await _apiService.updateUserImage( image, - AuthSharedPrefs.getAccessToken(), ); return ApiResult.success(response); } catch (error) {