import 'package:cheminova/utils/api_urls.dart'; import 'package:cheminova/utils/common_api_service.dart'; import 'package:cheminova/utils/show_snackbar.dart'; import 'package:dio/dio.dart'; import 'package:pretty_dio_logger/pretty_dio_logger.dart'; import '../../../utils/app_interceptor.dart'; class AuthService { final Dio _dio; AuthService() : _dio = Dio(BaseOptions(baseUrl: 'https://api.cnapp.co.in')) { _dio.interceptors.add(AuthInterceptor()); _dio.interceptors.add(PrettyDioLogger()); } // Function to handle user login Future?> login(Map data) async { try { // Making a POST request to the login URL using the common API service final response = await commonApiService>( url: ApiUrls.loginUrl, method: 'POST', body: data, fromJson: (json) => json, // Simply return the JSON map as is ); return response; } catch (e) { showSnackbar(e.toString()); } return null; } // Function to handle forgot password functionality // Function to handle password change functionality Future?> forgotPassword(Map data) async { try { // Making a POST request to the forgot password URL using the common API service final response = await commonApiService>( url: ApiUrls.forgetPasswordUrl, method: 'POST', body: data, fromJson: (json) => json, // Simply return the JSON map as is ); return response; } catch (e) { showSnackbar(e.toString()); } return null; } // Function to handle password change functionality Future?> changePassword(Map data, {required String token}) async { try { // Making a PUT request to the change password URL using the common API service final response = await commonApiService>( url: ApiUrls.changePasswordUrl, 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; } }