update api

This commit is contained in:
Phuoc Nguyen
2025-10-10 17:15:40 +07:00
parent b94c158004
commit 04f7042b8d
24 changed files with 3322 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ import 'api_interceptor.dart';
/// Dio HTTP client configuration
class DioClient {
late final Dio _dio;
String? _authToken;
DioClient() {
_dio = Dio(
@@ -21,10 +22,35 @@ class DioClient {
);
_dio.interceptors.add(ApiInterceptor());
// Add auth interceptor to inject token
_dio.interceptors.add(
InterceptorsWrapper(
onRequest: (options, handler) {
if (_authToken != null) {
options.headers[ApiConstants.authorization] = 'Bearer $_authToken';
}
return handler.next(options);
},
),
);
}
Dio get dio => _dio;
/// Set authentication token for all future requests
void setAuthToken(String token) {
_authToken = token;
}
/// Clear authentication token
void clearAuthToken() {
_authToken = null;
}
/// Check if auth token is set
bool get hasAuthToken => _authToken != null;
/// GET request
Future<Response> get(
String path, {