TF-928 Fix force logout when reload web

This commit is contained in:
dab246
2022-09-08 13:01:19 +07:00
committed by Dat H. Pham
parent 0838530775
commit aab8967c27
6 changed files with 26 additions and 27 deletions
@@ -98,14 +98,16 @@ class AuthenticationInfoCacheClient extends HiveCacheClient<AuthenticationInfoCa
@override
Future<Box<AuthenticationInfoCache>> openBox() async {
return Future.sync(() async {
final encryptionKey = await getEncryptionKey();
final encryptionKey = await getEncryptionKey();
if (Hive.isBoxOpen(tableName)) {
return Hive.box<AuthenticationInfoCache>(tableName);
} else {
return Hive.openBox<AuthenticationInfoCache>(
tableName,
encryptionCipher: HiveAesCipher(encryptionKey!));
}).catchError((error) {
throw error;
});
encryptionCipher: encryptionKey != null
? HiveAesCipher(encryptionKey)
: null);
}
}
@override
@@ -2,7 +2,6 @@
import 'package:flutter/foundation.dart';
import 'package:tmail_ui_user/features/caching/account_cache_client.dart';
import 'package:tmail_ui_user/features/caching/email_cache_client.dart';
import 'package:tmail_ui_user/features/caching/encryption_key_cache_client.dart';
import 'package:tmail_ui_user/features/caching/mailbox_cache_client.dart';
import 'package:tmail_ui_user/features/caching/recent_search_cache_client.dart';
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
@@ -14,7 +13,6 @@ class CachingManager {
final EmailCacheClient _emailCacheClient;
final RecentSearchCacheClient _recentSearchCacheClient;
final AccountCacheClient _accountCacheClient;
final EncryptionKeyCacheClient _encryptionKeyCacheClient;
CachingManager(
this._mailboxCacheClient,
@@ -22,7 +20,6 @@ class CachingManager {
this._emailCacheClient,
this._recentSearchCacheClient,
this._accountCacheClient,
this._encryptionKeyCacheClient,
);
Future<void> clearAll() async {
@@ -33,7 +30,6 @@ class CachingManager {
_emailCacheClient.clearAllData(),
_recentSearchCacheClient.clearAllData(),
_accountCacheClient.clearAllData(),
_encryptionKeyCacheClient.clearAllData(),
]);
} else {
await Future.wait([
@@ -42,7 +38,6 @@ class CachingManager {
_emailCacheClient.deleteBox(),
_recentSearchCacheClient.deleteBox(),
_accountCacheClient.deleteBox(),
_encryptionKeyCacheClient.deleteBox(),
]);
}
}
@@ -42,7 +42,7 @@ class HiveCacheConfig {
final encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
if (encryptionKeyCache == null) {
final secureKey = Hive.generateSecureKey();
final secureKeyEncode = base64UrlEncode(secureKey);
final secureKeyEncode = base64Encode(secureKey);
log('HiveCacheConfig::_initializeEncryptionKey(): secureKeyEncode: $secureKeyEncode');
await encryptionKeyCacheManager.storeEncryptionKey(EncryptionKeyCache(secureKeyEncode));
}
@@ -51,15 +51,12 @@ class HiveCacheConfig {
static Future<Uint8List?> getEncryptionKey() async {
final encryptionKeyCacheManager = Get.find<EncryptionKeyCacheManager>();
var encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
if (encryptionKeyCache == null) {
await initializeEncryptionKey();
encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
}
if (encryptionKeyCache != null) {
log('HiveCacheConfig::getEncryptionKey(): encryptionKey: ${encryptionKeyCache.value}');
final encryptionKey = base64Url.decode(encryptionKeyCache.value);
return encryptionKey;
final encryptionKey = encryptionKeyCache.value;
log('HiveCacheConfig::getEncryptionKey(): encryptionKey: $encryptionKey');
final encryptionKeyDecode = base64Decode(encryptionKeyCache.value);
return encryptionKeyDecode;
} else {
return null;
}
@@ -98,7 +98,11 @@ class EncryptionKeyCacheClient extends HiveCacheClient<EncryptionKeyCache> {
@override
Future<Box<EncryptionKeyCache>> openBox() async {
return Hive.openBox<EncryptionKeyCache>(tableName);
if (Hive.isBoxOpen(tableName)) {
return Hive.box<EncryptionKeyCache>(tableName);
} else {
return Hive.openBox<EncryptionKeyCache>(tableName);
}
}
@override
@@ -98,14 +98,16 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
@override
Future<Box<TokenOidcCache>> openBox() async {
return Future.sync(() async {
final encryptionKey = await getEncryptionKey();
final encryptionKey = await getEncryptionKey();
if (Hive.isBoxOpen(tableName)) {
return Hive.box<TokenOidcCache>(tableName);
} else {
return Hive.openBox<TokenOidcCache>(
tableName,
encryptionCipher: HiveAesCipher(encryptionKey!));
}).catchError((error) {
throw error;
});
encryptionCipher: encryptionKey != null
? HiveAesCipher(encryptionKey)
: null);
}
}
@override
@@ -57,7 +57,6 @@ class LocalBindings extends Bindings {
Get.find<EmailCacheClient>(),
Get.find<RecentSearchCacheClient>(),
Get.find<AccountCacheClient>(),
Get.find<EncryptionKeyCacheClient>(),
));
}
}