Skip to content

Commit

Permalink
fix auth interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dnys1 committed Apr 5, 2024
1 parent 405d0e1 commit e3d259f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
12 changes: 6 additions & 6 deletions packages/celest_auth/lib/src/auth_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -83,7 +83,7 @@ final class AuthImpl implements Auth {
@override
Future<void> signOut() async {
localStorage.delete('userId');
secureStorage.isolated.delete('cork').ignore();
secureStorage.delete('cork').ignore();
try {
await protocol.signOut();
} finally {
Expand All @@ -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<void> close() async {
localStorage.close();
secureStorage.close();
await _authStateSubscription.cancel();
await _authFlowSubscription?.cancel();
await _authStateController.close();
localStorage.close();
await secureStorage.close();
}
}
13 changes: 6 additions & 7 deletions packages/celest_core/lib/src/http/celest_http_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<http.StreamedResponse> 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);
}
Expand Down

0 comments on commit e3d259f

Please sign in to comment.