diff --git a/packages/celest_auth/lib/src/auth_impl.dart b/packages/celest_auth/lib/src/auth_impl.dart index 42aee07f..0460990e 100644 --- a/packages/celest_auth/lib/src/auth_impl.dart +++ b/packages/celest_auth/lib/src/auth_impl.dart @@ -12,8 +12,8 @@ export 'flows/email_flow.dart'; final class AuthImpl implements Auth { AuthImpl( this.celest, { - required NativeStorage storage, - }) : _storage = storage.scoped('auth'); + NativeStorage? storage, + }) : _storage = storage ?? NativeStorage(scope: 'celest/auth'); AuthState? _authState; @@ -83,7 +83,7 @@ final class AuthImpl implements Auth { @override Future signOut() async { localStorage.delete('userId'); - secureStorage.isolated.delete('cork').ignore(); + secureStorage.delete('cork').ignore(); try { await protocol.signOut(); } finally { @@ -95,15 +95,15 @@ final class AuthImpl implements Auth { final NativeStorage _storage; NativeStorage get localStorage => _storage; - NativeSecureStorage get secureStorage => _storage.secure; + IsolatedNativeStorage get secureStorage => _storage.secure.isolated; late final AuthClient protocol = AuthClient(celest); Future close() async { - localStorage.close(); - secureStorage.close(); await _authStateSubscription.cancel(); await _authFlowSubscription?.cancel(); await _authStateController.close(); + localStorage.close(); + await secureStorage.close(); } } 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 5d2cf475..193d06d1 100644 --- a/packages/celest_core/lib/src/http/celest_http_client.dart +++ b/packages/celest_core/lib/src/http/celest_http_client.dart @@ -7,21 +7,20 @@ final class CelestHttpClient extends http.BaseClient { CelestHttpClient({ NativeSecureStorage? secureStorage, http.Client? baseClient, - }) : _secureStorage = secureStorage, + }) : _secureStorage = + secureStorage ?? NativeSecureStorage(scope: 'celest/auth'), _ownsInner = baseClient == null, _inner = baseClient ?? createHttpClient(); - final NativeSecureStorage? _secureStorage; + final NativeSecureStorage _secureStorage; final bool _ownsInner; final http.Client _inner; @override Future send(http.BaseRequest request) async { - if (_secureStorage != null) { - final cork = await _secureStorage.isolated.read('auth/cork'); - if (cork != null) { - request.headers['authorization'] = 'Bearer $cork'; - } + final cork = await _secureStorage.isolated.read('cork'); + if (cork != null) { + request.headers['authorization'] = 'Bearer $cork'; } return _inner.send(request); }