53 lines
1.5 KiB
Dart
53 lines
1.5 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:get_it/get_it.dart';
|
|
import '../api/api_client.dart';
|
|
import '../storage/token_storage.dart';
|
|
import '../config/env.dart';
|
|
import '../../features/auth/data/auth_api.dart';
|
|
import '../../features/auth/data/auth_repository.dart';
|
|
import '../../features/auth/data/auth_repository_impl.dart';
|
|
import '../../features/auth/presentation/bloc/auth_bloc.dart';
|
|
|
|
final sl = GetIt.instance;
|
|
|
|
Future<void> configureDependencies() async {
|
|
final dio = Dio(BaseOptions(baseUrl: Env.apiUrl));
|
|
final secureStorage = const FlutterSecureStorage();
|
|
final tokenStorage = SecureTokenStorage(secureStorage);
|
|
|
|
sl.registerSingleton<Dio>(dio);
|
|
sl.registerSingleton<FlutterSecureStorage>(secureStorage);
|
|
sl.registerSingleton<TokenStorage>(tokenStorage);
|
|
|
|
final authApi = AuthApi(
|
|
ApiClient(baseUrl: Env.apiUrl, tokenStorage: tokenStorage, dio: dio),
|
|
);
|
|
sl.registerSingleton<AuthApi>(authApi);
|
|
|
|
final authRepository = AuthRepositoryImpl(
|
|
api: authApi,
|
|
tokenStorage: tokenStorage,
|
|
);
|
|
sl.registerSingleton<AuthRepository>(authRepository);
|
|
|
|
sl.unregister<ApiClient>();
|
|
sl.registerSingleton<ApiClient>(
|
|
ApiClient(
|
|
baseUrl: Env.apiUrl,
|
|
tokenStorage: tokenStorage,
|
|
dio: dio,
|
|
refreshToken: (token) async {
|
|
try {
|
|
await authRepository.refresh(token);
|
|
return true;
|
|
} catch (_) {
|
|
return false;
|
|
}
|
|
},
|
|
),
|
|
);
|
|
|
|
sl.registerSingleton<AuthBloc>(AuthBloc(authRepository));
|
|
}
|