diff --git a/lib/injection/config_module.dart b/lib/injection/config_module.dart index fcbe1e3..ae26e3e 100644 --- a/lib/injection/config_module.dart +++ b/lib/injection/config_module.dart @@ -6,6 +6,8 @@ import 'package:flutter_template/presentation/app_flavor.dart'; import 'package:flutter_template/presentation/application_config.dart'; abstract class ConfigModule { + /// Can't use injectable with preresolve as it fails with a stack overflow exception + /// because here we depend on the flutter/services package. static Future inject(AppFlavor flavor) async { const basePath = 'assets/configuration/application_configuration'; final configPath = '$basePath.${flavor.name}.json'; diff --git a/lib/injection/network_module.dart b/lib/injection/network_module.dart index a11b050..2a95f95 100644 --- a/lib/injection/network_module.dart +++ b/lib/injection/network_module.dart @@ -1,15 +1,17 @@ import 'package:dio/adapter.dart'; import 'package:dio/dio.dart'; import 'package:flutter_template/data/api/api_config.dart'; -import 'package:flutter_template/data/interceptor/auth_interceptor.dart'; +import 'package:flutter_template/data/api/new/authenticator/authenticator.dart'; +import 'package:flutter_template/data/api/new/interceptor/api_auth_interceptor.dart'; import 'package:flutter_template/data/services/http_client/dio_http_client.dart'; import 'package:flutter_template/injection/injector.dart'; import 'package:injectable/injectable.dart'; const dioAuth = 'AUTH'; const dioRegular = 'REGULAR'; +const authDioClient = 'AUTHDIOCLIENT'; -Dio _getBaseDio(ApiConfig apiConfig) { +Dio _createBaseDio(ApiConfig apiConfig) { final dio = Dio() ..httpClientAdapter = DefaultHttpClientAdapter() ..options.baseUrl = apiConfig.apiUrl; @@ -19,34 +21,25 @@ Dio _getBaseDio(ApiConfig apiConfig) { @module abstract class NetworkModule { + @singleton + @Named(authDioClient) + DioHttpClient getAuthDioClient(ApiConfig apiConfig) { + final dio = _createBaseDio(apiConfig); + return DioHttpClient(dio); + } + @singleton @Named(dioAuth) Dio getAuthDio(ApiConfig apiConfig) { - final dio = _getBaseDio(apiConfig); + final dio = _createBaseDio(apiConfig); return dio; } @singleton @Named(dioRegular) - Dio getRegularDio(ApiConfig apiConfig) { - final dio = _getBaseDio(apiConfig); - - final httpClient = DioHttpClient(dio); - final refreshTokenHttpClient = DioHttpClient( - injector.get(instanceName: dioRegular), - ); - - dio.interceptors.add( - AuthInterceptor( - httpClient: httpClient, - refreshTokenHttpClient: refreshTokenHttpClient, - authPreferences: injector(), - userPreferences: injector(), - onTokenExpired: () { - // TODO: Handle log out - }, - ), - ); + Dio getRegularDio(ApiConfig apiConfig, Authenticator authenticator) { + final dio = _createBaseDio(apiConfig) + ..interceptors.add(injector()); return dio; }