diff --git a/CHANGELOG.md b/CHANGELOG.md index fc5d13f..1981ccf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.0.1] - 2026-01-03 + +### Fixed +- Web authentication now works correctly with NPM forward auth + - Dio client sends cookies with requests via `withCredentials: true` + - Added platform-specific adapters (native vs web) for proper cookie handling + ## [1.0.0] - 2026-01-03 ### Added diff --git a/lib/core/api/api_client.dart b/lib/core/api/api_client.dart index 43a2168..6ee647f 100644 --- a/lib/core/api/api_client.dart +++ b/lib/core/api/api_client.dart @@ -3,23 +3,26 @@ 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 dio = Dio( - BaseOptions( - baseUrl: AppConfig.coreApiUrl, - connectTimeout: const Duration(seconds: 10), - receiveTimeout: const Duration(seconds: 30), - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - }, - ), + 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(), @@ -32,18 +35,18 @@ Dio coreApiClient(Ref ref) { /// Provides the Dio instance for Tatlock API. @riverpod Dio tatlockApiClient(Ref ref) { - final dio = Dio( - 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 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(), diff --git a/lib/core/api/api_client_native.dart b/lib/core/api/api_client_native.dart new file mode 100644 index 0000000..44b69a8 --- /dev/null +++ b/lib/core/api/api_client_native.dart @@ -0,0 +1,6 @@ +import 'package:dio/dio.dart'; + +/// Create a Dio instance for native platforms (mobile, desktop). +Dio createDio(BaseOptions options) { + return Dio(options); +} diff --git a/lib/core/api/api_client_web.dart b/lib/core/api/api_client_web.dart new file mode 100644 index 0000000..43f07cf --- /dev/null +++ b/lib/core/api/api_client_web.dart @@ -0,0 +1,12 @@ +import 'package:dio/dio.dart'; +import 'package:dio_web_adapter/dio_web_adapter.dart'; + +/// Create a Dio instance for web platform with credentials support. +/// +/// Enables `withCredentials` to send cookies with requests, which is +/// required for NPM forward auth to work correctly. +Dio createDio(BaseOptions options) { + final dio = Dio(options); + dio.httpClientAdapter = BrowserHttpClientAdapter(withCredentials: true); + return dio; +} diff --git a/pubspec.yaml b/pubspec.yaml index cf1e9df..4dbad4e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html # In Windows, build-name is used as the major, minor, and patch parts # of the product and file versions while build-number is used as the build suffix. -version: 1.0.0+1 +version: 1.0.1+1 environment: sdk: ^3.10.4 @@ -67,6 +67,7 @@ dependencies: url_launcher: ^6.3.1 flutter_code_editor: ^0.3.5 highlight: ^0.7.0 + dio_web_adapter: ^2.1.1 dev_dependencies: flutter_test: