TF-1317 Update authentication account to store AccountId

This commit is contained in:
dab246
2023-01-04 19:00:53 +07:00
committed by Dat H. Pham
parent eadc0c4ddc
commit 6566372337
21 changed files with 193 additions and 71 deletions
@@ -1,3 +1,5 @@
import 'package:jmap_dart_client/jmap/account_id.dart';
import 'package:jmap_dart_client/jmap/core/id.dart';
import 'package:model/account/account.dart';
import 'package:model/account/authentication_type.dart';
import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
@@ -15,6 +17,12 @@ extension AccountCacheExtension on AccountCache {
Account toAccount() {
final authenticationType = fromAuthenticationTypeString();
return Account(id, authenticationType, isSelected: isSelected);
return Account(
id,
authenticationType,
isSelected: isSelected,
accountId: accountId != null ? AccountId(Id(accountId!)) : null,
apiUrl: apiUrl
);
}
}
@@ -4,6 +4,12 @@ import 'package:tmail_ui_user/features/login/data/model/account_cache.dart';
extension AccountExtensions on Account {
AccountCache toCache() {
return AccountCache(id, authenticationType.asString(), isSelected: isSelected);
return AccountCache(
id,
authenticationType.asString(),
isSelected: isSelected,
accountId: accountId?.id.value,
apiUrl: apiUrl
);
}
}
@@ -15,8 +15,28 @@ class AccountCache extends HiveObject with EquatableMixin {
@HiveField(2)
final bool isSelected;
AccountCache(this.id, this.authenticationType, {required this.isSelected});
@HiveField(3)
final String? accountId;
@HiveField(4)
final String? apiUrl;
AccountCache(
this.id,
this.authenticationType,
{
required this.isSelected,
this.accountId,
this.apiUrl
}
);
@override
List<Object?> get props => [id, authenticationType, isSelected];
List<Object?> get props => [
id,
authenticationType,
isSelected,
accountId,
apiUrl
];
}
@@ -88,13 +88,18 @@ class AuthorizationInterceptors extends InterceptorsWrapper {
_configOIDC!.scopes,
_token!.refreshToken);
final accountCurrent = await _accountCacheManager.getSelectedAccount();
await Future.wait([
_tokenOidcCacheManager.persistOneTokenOidc(newToken),
_accountCacheManager.deleteSelectedAccount(_token!.tokenIdHash),
_accountCacheManager.setSelectedAccount(Account(
newToken.tokenIdHash,
AuthenticationType.oidc,
isSelected: true)),
newToken.tokenIdHash,
AuthenticationType.oidc,
isSelected: true,
accountId: accountCurrent.accountId,
apiUrl: accountCurrent.apiUrl
)),
]);
log('AuthorizationInterceptors::onError(): refreshToken: $newToken');