TF-886 Clear AuthenticationInfo

This commit is contained in:
dab246
2022-09-06 19:13:15 +07:00
committed by Dat H. Pham
parent f108f5c726
commit 37d36e90a4
7 changed files with 26 additions and 19 deletions
@@ -11,6 +11,7 @@ class AuthenticationInfoCacheClient extends HiveCacheClient<AuthenticationInfoCa
@override @override
Future<void> clearAllData() { Future<void> clearAllData() {
return Future.sync(() async { return Future.sync(() async {
await HiveCacheConfig.removeEncryptionKey();
final boxAuthenticationInfo = await openBox(); final boxAuthenticationInfo = await openBox();
return boxAuthenticationInfo.clear(); return boxAuthenticationInfo.clear();
}).catchError((error) { }).catchError((error) {
+8 -3
View File
@@ -1,6 +1,7 @@
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/authentication_info_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/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';
@@ -15,6 +16,7 @@ class CachingManager {
final RecentSearchCacheClient _recentSearchCacheClient; final RecentSearchCacheClient _recentSearchCacheClient;
final TokenOidcCacheClient _tokenOidcCacheClient; final TokenOidcCacheClient _tokenOidcCacheClient;
final AccountCacheClient _accountCacheClient; final AccountCacheClient _accountCacheClient;
final AuthenticationInfoCacheClient _authenticationInfoCacheClient;
CachingManager( CachingManager(
this._mailboxCacheClient, this._mailboxCacheClient,
@@ -22,7 +24,8 @@ class CachingManager {
this._emailCacheClient, this._emailCacheClient,
this._recentSearchCacheClient, this._recentSearchCacheClient,
this._tokenOidcCacheClient, this._tokenOidcCacheClient,
this._accountCacheClient this._accountCacheClient,
this._authenticationInfoCacheClient,
); );
Future<void> clearAll() async { Future<void> clearAll() async {
@@ -33,7 +36,8 @@ class CachingManager {
_emailCacheClient.clearAllData(), _emailCacheClient.clearAllData(),
_recentSearchCacheClient.clearAllData(), _recentSearchCacheClient.clearAllData(),
_tokenOidcCacheClient.clearAllData(), _tokenOidcCacheClient.clearAllData(),
_accountCacheClient.clearAllData() _accountCacheClient.clearAllData(),
_authenticationInfoCacheClient.clearAllData(),
]); ]);
} else { } else {
await Future.wait([ await Future.wait([
@@ -42,7 +46,8 @@ class CachingManager {
_emailCacheClient.deleteBox(), _emailCacheClient.deleteBox(),
_recentSearchCacheClient.deleteBox(), _recentSearchCacheClient.deleteBox(),
_tokenOidcCacheClient.deleteBox(), _tokenOidcCacheClient.deleteBox(),
_accountCacheClient.deleteBox() _accountCacheClient.deleteBox(),
_authenticationInfoCacheClient.deleteBox(),
]); ]);
} }
} }
@@ -50,6 +50,11 @@ class HiveCacheConfig {
return encryptionKey; return encryptionKey;
} }
static Future<bool> removeEncryptionKey() {
final sharedPreference = Get.find<SharedPreferences>();
return sharedPreference.remove(LoginConstant.keyHiveEncrypt);
}
void registerAdapter() { void registerAdapter() {
Hive.registerAdapter(MailboxCacheAdapter()); Hive.registerAdapter(MailboxCacheAdapter());
Hive.registerAdapter(MailboxRightsCacheAdapter()); Hive.registerAdapter(MailboxRightsCacheAdapter());
@@ -15,4 +15,8 @@ class AuthenticationInfoCacheManager {
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() { Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue); return _authenticationInfoCacheClient.getItem(AuthenticationInfoCache.keyCacheValue);
} }
Future<void> removeAuthenticationInfo() {
return _authenticationInfoCacheClient.deleteItem(AuthenticationInfoCache.keyCacheValue);
}
} }
@@ -32,16 +32,6 @@ class CredentialRepositoryImpl extends CredentialRepository {
await sharedPreferences.remove(LoginConstant.keyBaseUrl); await sharedPreferences.remove(LoginConstant.keyBaseUrl);
} }
@override
Future removePassword() async {
await sharedPreferences.remove(LoginConstant.keyPassword);
}
@override
Future removeUserName() async {
await sharedPreferences.remove(LoginConstant.keyUserName);
}
@override @override
Future<UserProfile> getUserProfile() async { Future<UserProfile> getUserProfile() async {
final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? ''; final json = sharedPreferences.getString(LoginConstant.keyUserProfile) ?? '';
@@ -70,4 +60,9 @@ class CredentialRepositoryImpl extends CredentialRepository {
Future<AuthenticationInfoCache?> getAuthenticationInfoStored() { Future<AuthenticationInfoCache?> getAuthenticationInfoStored() {
return _authenticationInfoCacheManager.getAuthenticationInfoStored(); return _authenticationInfoCacheManager.getAuthenticationInfoStored();
} }
@override
Future<void> removeAuthenticationInfo() {
return _authenticationInfoCacheManager.removeAuthenticationInfo();
}
} }
@@ -8,10 +8,6 @@ abstract class CredentialRepository {
Future<Uri> getBaseUrl(); Future<Uri> getBaseUrl();
Future removeUserName();
Future removePassword();
Future saveUserProfile(UserProfile userProfile); Future saveUserProfile(UserProfile userProfile);
Future removeUserProfile(); Future removeUserProfile();
@@ -21,4 +17,6 @@ abstract class CredentialRepository {
Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache); Future<void> storeAuthenticationInfo(AuthenticationInfoCache authenticationInfoCache);
Future<AuthenticationInfoCache?> getAuthenticationInfoStored(); Future<AuthenticationInfoCache?> getAuthenticationInfoStored();
Future<void> removeAuthenticationInfo();
} }
@@ -14,8 +14,7 @@ class DeleteCredentialInteractor {
try { try {
await Future.wait([ await Future.wait([
credentialRepository.removeBaseUrl(), credentialRepository.removeBaseUrl(),
credentialRepository.removeUserName(), credentialRepository.removeAuthenticationInfo(),
credentialRepository.removePassword(),
credentialRepository.removeUserProfile(), credentialRepository.removeUserProfile(),
]); ]);
return Right(DeleteCredentialSuccess()); return Right(DeleteCredentialSuccess());