Configure Dio with BrowserHttpClientAdapter and withCredentials: true for web platform, allowing session cookies to be sent with XHR requests. This fixes NPM forward auth not working for API calls. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
58 lines
1.4 KiB
Dart
58 lines
1.4 KiB
Dart
import 'package:dio/dio.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
import 'package:tatlock_ui/core/api/api_interceptors.dart';
|
|
import 'package:tatlock_ui/core/config/app_config.dart';
|
|
|
|
import 'api_client_native.dart' if (dart.library.html) 'api_client_web.dart'
|
|
as platform;
|
|
|
|
part 'api_client.g.dart';
|
|
|
|
/// Provides the Dio instance for Core API.
|
|
@riverpod
|
|
Dio coreApiClient(Ref ref) {
|
|
final options = BaseOptions(
|
|
baseUrl: AppConfig.coreApiUrl,
|
|
connectTimeout: const Duration(seconds: 10),
|
|
receiveTimeout: const Duration(seconds: 30),
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
},
|
|
);
|
|
|
|
final dio = platform.createDio(options);
|
|
|
|
dio.interceptors.addAll([
|
|
AuthInterceptor(ref),
|
|
LoggingInterceptor(),
|
|
ErrorInterceptor(),
|
|
]);
|
|
|
|
return dio;
|
|
}
|
|
|
|
/// Provides the Dio instance for Tatlock API.
|
|
@riverpod
|
|
Dio tatlockApiClient(Ref ref) {
|
|
final options = BaseOptions(
|
|
baseUrl: AppConfig.tatlockApiUrl,
|
|
connectTimeout: const Duration(seconds: 10),
|
|
receiveTimeout: const Duration(minutes: 5), // Longer for LLM responses
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
'Accept': 'application/json',
|
|
},
|
|
);
|
|
|
|
final dio = platform.createDio(options);
|
|
|
|
dio.interceptors.addAll([
|
|
AuthInterceptor(ref),
|
|
LoggingInterceptor(),
|
|
ErrorInterceptor(),
|
|
]);
|
|
|
|
return dio;
|
|
}
|