From fbbc101a5581ab2a65f31a0345d2a29350a85d51 Mon Sep 17 00:00:00 2001 From: Dillon Nys Date: Sat, 9 Mar 2024 15:05:49 -0800 Subject: [PATCH] chore(core): Allow credentials in browser environments This is needed to use cookies. --- packages/celest_core/lib/src/http/celest_http_client.dart | 4 +++- packages/celest_core/lib/src/http/http_client.vm.dart | 5 +++++ packages/celest_core/lib/src/http/http_client.web.dart | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 packages/celest_core/lib/src/http/http_client.vm.dart create mode 100644 packages/celest_core/lib/src/http/http_client.web.dart diff --git a/packages/celest_core/lib/src/http/celest_http_client.dart b/packages/celest_core/lib/src/http/celest_http_client.dart index e276eb9f..c8c33d66 100644 --- a/packages/celest_core/lib/src/http/celest_http_client.dart +++ b/packages/celest_core/lib/src/http/celest_http_client.dart @@ -1,5 +1,7 @@ import 'dart:isolate'; +import 'package:celest_core/src/http/http_client.vm.dart' + if (dart.library.js_interop) 'package:celest_core/src/http/http_client.web.dart'; import 'package:celest_core/src/storage/secure/secure_storage.dart'; import 'package:celest_core/src/storage/storage.dart'; import 'package:celest_core/src/util/globals.dart'; @@ -11,7 +13,7 @@ final class CelestHttpClient extends http.BaseClient { http.Client? baseClient, }) : _secureStorage = secureStorage, _ownsInner = baseClient == null, - _inner = baseClient ?? http.Client(); + _inner = baseClient ?? createHttpClient(); final SecureStorage _secureStorage; final bool _ownsInner; diff --git a/packages/celest_core/lib/src/http/http_client.vm.dart b/packages/celest_core/lib/src/http/http_client.vm.dart new file mode 100644 index 00000000..e96f5b64 --- /dev/null +++ b/packages/celest_core/lib/src/http/http_client.vm.dart @@ -0,0 +1,5 @@ +import 'package:http/http.dart' as http; + +http.Client createHttpClient() { + return http.Client(); +} diff --git a/packages/celest_core/lib/src/http/http_client.web.dart b/packages/celest_core/lib/src/http/http_client.web.dart new file mode 100644 index 00000000..584c1175 --- /dev/null +++ b/packages/celest_core/lib/src/http/http_client.web.dart @@ -0,0 +1,6 @@ +import 'package:http/browser_client.dart' as http; +import 'package:http/http.dart' as http; + +http.Client createHttpClient() { + return http.BrowserClient()..withCredentials = true; +}