-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
78 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
packages/celest_core/lib/src/secure_storage/secure_storage.stub.dart
This file was deleted.
Oops, something went wrong.
43 changes: 35 additions & 8 deletions
43
packages/celest_core/lib/src/secure_storage/secure_storage_platform.web.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,42 @@ | ||
import 'package:celest_core/src/secure_storage/secure_storage.dart'; | ||
import 'package:celest_core/src/secure_storage/secure_storage.stub.dart'; | ||
import 'package:meta/meta.dart'; | ||
import 'package:web/web.dart' as web; | ||
|
||
abstract base class SecureStoragePlatform implements SecureStorage { | ||
factory SecureStoragePlatform({ | ||
final class SecureStoragePlatform implements SecureStorage { | ||
SecureStoragePlatform({ | ||
String? scope, | ||
}) => | ||
SecureStoragePlatformStub(scope: scope ?? _defaultScope); | ||
}) : scope = scope ?? _defaultScope; | ||
|
||
final String scope; | ||
|
||
static const _defaultScope = 'dev.celest.celest'; | ||
|
||
@protected | ||
const SecureStoragePlatform.base(); | ||
List<String> get _keys => [ | ||
for (var i = 0; i < web.window.localStorage.length; i++) | ||
web.window.localStorage.key(i)!, | ||
]; | ||
|
||
@override | ||
void clear() { | ||
for (final key in _keys) { | ||
if (key.startsWith('$scope/')) { | ||
web.window.localStorage.removeItem(key); | ||
} | ||
} | ||
} | ||
|
||
@override | ||
String? delete(String key) { | ||
final value = read(key); | ||
web.window.localStorage.removeItem('$scope/$key'); | ||
return value; | ||
} | ||
|
||
@override | ||
String? read(String key) => web.window.localStorage.getItem('$scope/$key'); | ||
|
||
@override | ||
String write(String key, String value) { | ||
web.window.localStorage.setItem('$scope/$key', value); | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters