Created
April 8, 2019 22:38
-
-
Save Vortexmind/c3551cbe41493ab735b403669b962ed1 to your computer and use it in GitHub Desktop.
CognitoSecureStorage for Amazon Cognito Identity Dart ( https://pub.dartlang.org/packages/amazon_cognito_identity_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
import 'package:amazon_cognito_identity_dart/cognito.dart'; | |
import 'package:flutter_secure_storage/flutter_secure_storage.dart'; | |
import 'dart:convert'; | |
class CognitoSecureStorage extends CognitoStorage { | |
FlutterSecureStorage _securePrefs = new FlutterSecureStorage(); | |
CognitoSecureStorage(); | |
@override | |
Future getItem(String key) async { | |
String item; | |
try { | |
item = json.decode(await _securePrefs.read(key: key)); | |
} catch (e) { | |
return null; | |
} | |
return item; | |
} | |
@override | |
Future setItem(String key, value) async { | |
_securePrefs.write(key: key, value: json.encode(value)); | |
return getItem(key); | |
} | |
@override | |
Future removeItem(String key) async { | |
final item = getItem(key); | |
if (item != null) { | |
_securePrefs.delete(key: key); | |
return item; | |
} | |
return null; | |
} | |
@override | |
Future<void> clear() async { | |
_securePrefs.deleteAll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment