feat : remember me for chicken module
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:rasadyar_core/hive_registrar.g.dart';
|
||||
|
||||
class TokenStorageService extends GetxService {
|
||||
static const String _tokenBoxName = 'TokenBox';
|
||||
static const String _userPassBox = 'UserPassBox';
|
||||
static const String _appBoxName = 'AppBox';
|
||||
static const String _accessTokenKey = 'accessToken';
|
||||
static const String _refreshTokenKey = 'refreshToken';
|
||||
@@ -21,7 +22,6 @@ class TokenStorageService extends GetxService {
|
||||
Rxn<Module> appModule = Rxn(null);
|
||||
|
||||
Future<void> init() async {
|
||||
|
||||
Hive.registerAdapters();
|
||||
|
||||
final String? encryptedKey = await _secureStorage.read(key: 'hive_enc_key');
|
||||
@@ -36,6 +36,7 @@ class TokenStorageService extends GetxService {
|
||||
await _localStorage.init();
|
||||
await _localStorage.openBox(_tokenBoxName, encryptionCipher: HiveAesCipher(encryptionKey));
|
||||
await _localStorage.openBox(_appBoxName);
|
||||
await _localStorage.openBox<UserLocalModel>(_userPassBox);
|
||||
|
||||
accessToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _accessTokenKey);
|
||||
refreshToken.value = _localStorage.read<String?>(boxName: _tokenBoxName, key: _refreshTokenKey);
|
||||
@@ -88,4 +89,18 @@ class TokenStorageService extends GetxService {
|
||||
Future<void> saveApiKey(String key) async {
|
||||
await _localStorage.save(boxName: _tokenBoxName, key: _apiKey, value: key);
|
||||
}
|
||||
|
||||
Future<void> saveUserPass(UserLocalModel model) async {
|
||||
await _localStorage.save<UserLocalModel>(
|
||||
boxName: _userPassBox,
|
||||
key: model.module!.name,
|
||||
value: model,
|
||||
);
|
||||
}
|
||||
|
||||
UserLocalModel? getUserPass(Module module) {
|
||||
return _localStorage
|
||||
.readBox<UserLocalModel>(boxName: _userPassBox)
|
||||
?.firstWhereOrNull((element) => element.module == module);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user