TF-928 Fix force logout when reload web
This commit is contained in:
@@ -98,14 +98,16 @@ class AuthenticationInfoCacheClient extends HiveCacheClient<AuthenticationInfoCa
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<AuthenticationInfoCache>> openBox() async {
|
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>(
|
return Hive.openBox<AuthenticationInfoCache>(
|
||||||
tableName,
|
tableName,
|
||||||
encryptionCipher: HiveAesCipher(encryptionKey!));
|
encryptionCipher: encryptionKey != null
|
||||||
}).catchError((error) {
|
? HiveAesCipher(encryptionKey)
|
||||||
throw error;
|
: null);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/account_cache_client.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/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/mailbox_cache_client.dart';
|
||||||
import 'package:tmail_ui_user/features/caching/recent_search_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';
|
import 'package:tmail_ui_user/features/caching/state_cache_client.dart';
|
||||||
@@ -14,7 +13,6 @@ class CachingManager {
|
|||||||
final EmailCacheClient _emailCacheClient;
|
final EmailCacheClient _emailCacheClient;
|
||||||
final RecentSearchCacheClient _recentSearchCacheClient;
|
final RecentSearchCacheClient _recentSearchCacheClient;
|
||||||
final AccountCacheClient _accountCacheClient;
|
final AccountCacheClient _accountCacheClient;
|
||||||
final EncryptionKeyCacheClient _encryptionKeyCacheClient;
|
|
||||||
|
|
||||||
CachingManager(
|
CachingManager(
|
||||||
this._mailboxCacheClient,
|
this._mailboxCacheClient,
|
||||||
@@ -22,7 +20,6 @@ class CachingManager {
|
|||||||
this._emailCacheClient,
|
this._emailCacheClient,
|
||||||
this._recentSearchCacheClient,
|
this._recentSearchCacheClient,
|
||||||
this._accountCacheClient,
|
this._accountCacheClient,
|
||||||
this._encryptionKeyCacheClient,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Future<void> clearAll() async {
|
Future<void> clearAll() async {
|
||||||
@@ -33,7 +30,6 @@ class CachingManager {
|
|||||||
_emailCacheClient.clearAllData(),
|
_emailCacheClient.clearAllData(),
|
||||||
_recentSearchCacheClient.clearAllData(),
|
_recentSearchCacheClient.clearAllData(),
|
||||||
_accountCacheClient.clearAllData(),
|
_accountCacheClient.clearAllData(),
|
||||||
_encryptionKeyCacheClient.clearAllData(),
|
|
||||||
]);
|
]);
|
||||||
} else {
|
} else {
|
||||||
await Future.wait([
|
await Future.wait([
|
||||||
@@ -42,7 +38,6 @@ class CachingManager {
|
|||||||
_emailCacheClient.deleteBox(),
|
_emailCacheClient.deleteBox(),
|
||||||
_recentSearchCacheClient.deleteBox(),
|
_recentSearchCacheClient.deleteBox(),
|
||||||
_accountCacheClient.deleteBox(),
|
_accountCacheClient.deleteBox(),
|
||||||
_encryptionKeyCacheClient.deleteBox(),
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class HiveCacheConfig {
|
|||||||
final encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
|
final encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
|
||||||
if (encryptionKeyCache == null) {
|
if (encryptionKeyCache == null) {
|
||||||
final secureKey = Hive.generateSecureKey();
|
final secureKey = Hive.generateSecureKey();
|
||||||
final secureKeyEncode = base64UrlEncode(secureKey);
|
final secureKeyEncode = base64Encode(secureKey);
|
||||||
log('HiveCacheConfig::_initializeEncryptionKey(): secureKeyEncode: $secureKeyEncode');
|
log('HiveCacheConfig::_initializeEncryptionKey(): secureKeyEncode: $secureKeyEncode');
|
||||||
await encryptionKeyCacheManager.storeEncryptionKey(EncryptionKeyCache(secureKeyEncode));
|
await encryptionKeyCacheManager.storeEncryptionKey(EncryptionKeyCache(secureKeyEncode));
|
||||||
}
|
}
|
||||||
@@ -51,15 +51,12 @@ class HiveCacheConfig {
|
|||||||
static Future<Uint8List?> getEncryptionKey() async {
|
static Future<Uint8List?> getEncryptionKey() async {
|
||||||
final encryptionKeyCacheManager = Get.find<EncryptionKeyCacheManager>();
|
final encryptionKeyCacheManager = Get.find<EncryptionKeyCacheManager>();
|
||||||
var encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
|
var encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
|
||||||
if (encryptionKeyCache == null) {
|
|
||||||
await initializeEncryptionKey();
|
|
||||||
encryptionKeyCache = await encryptionKeyCacheManager.getEncryptionKeyStored();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (encryptionKeyCache != null) {
|
if (encryptionKeyCache != null) {
|
||||||
log('HiveCacheConfig::getEncryptionKey(): encryptionKey: ${encryptionKeyCache.value}');
|
final encryptionKey = encryptionKeyCache.value;
|
||||||
final encryptionKey = base64Url.decode(encryptionKeyCache.value);
|
log('HiveCacheConfig::getEncryptionKey(): encryptionKey: $encryptionKey');
|
||||||
return encryptionKey;
|
final encryptionKeyDecode = base64Decode(encryptionKeyCache.value);
|
||||||
|
return encryptionKeyDecode;
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,11 @@ class EncryptionKeyCacheClient extends HiveCacheClient<EncryptionKeyCache> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<EncryptionKeyCache>> openBox() async {
|
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
|
@override
|
||||||
|
|||||||
@@ -98,14 +98,16 @@ class TokenOidcCacheClient extends HiveCacheClient<TokenOidcCache> {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Box<TokenOidcCache>> openBox() async {
|
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>(
|
return Hive.openBox<TokenOidcCache>(
|
||||||
tableName,
|
tableName,
|
||||||
encryptionCipher: HiveAesCipher(encryptionKey!));
|
encryptionCipher: encryptionKey != null
|
||||||
}).catchError((error) {
|
? HiveAesCipher(encryptionKey)
|
||||||
throw error;
|
: null);
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
@@ -57,7 +57,6 @@ class LocalBindings extends Bindings {
|
|||||||
Get.find<EmailCacheClient>(),
|
Get.find<EmailCacheClient>(),
|
||||||
Get.find<RecentSearchCacheClient>(),
|
Get.find<RecentSearchCacheClient>(),
|
||||||
Get.find<AccountCacheClient>(),
|
Get.find<AccountCacheClient>(),
|
||||||
Get.find<EncryptionKeyCacheClient>(),
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user