From 63ad3c83732eff4fd71be7c8619d3b8ee5e55f2b Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Sep 2024 19:45:39 +0700 Subject: [PATCH] chore(mobile): invalidate api repository for new sign in instance (#12940) * chore(mobile): invalidate api repository for new sign in instasnce * add comments --- mobile/lib/utils/provider_utils.dart | 16 ++++++++++++++++ mobile/lib/widgets/forms/login/login_form.dart | 4 ++++ 2 files changed, 20 insertions(+) create mode 100644 mobile/lib/utils/provider_utils.dart diff --git a/mobile/lib/utils/provider_utils.dart b/mobile/lib/utils/provider_utils.dart new file mode 100644 index 0000000000..3eac55089d --- /dev/null +++ b/mobile/lib/utils/provider_utils.dart @@ -0,0 +1,16 @@ +import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/repositories/activity_api.repository.dart'; +import 'package:immich_mobile/repositories/album_api.repository.dart'; +import 'package:immich_mobile/repositories/asset_api.repository.dart'; +import 'package:immich_mobile/repositories/partner_api.repository.dart'; +import 'package:immich_mobile/repositories/person_api.repository.dart'; +import 'package:immich_mobile/repositories/user_api.repository.dart'; + +void invalidateAllApiRepositoryProviders(WidgetRef ref) { + ref.invalidate(userApiRepositoryProvider); + ref.invalidate(activityApiRepositoryProvider); + ref.invalidate(partnerApiRepositoryProvider); + ref.invalidate(albumApiRepositoryProvider); + ref.invalidate(personApiRepositoryProvider); + ref.invalidate(assetApiRepositoryProvider); +} diff --git a/mobile/lib/widgets/forms/login/login_form.dart b/mobile/lib/widgets/forms/login/login_form.dart index 14a4e89dd6..51383fe195 100644 --- a/mobile/lib/widgets/forms/login/login_form.dart +++ b/mobile/lib/widgets/forms/login/login_form.dart @@ -16,6 +16,7 @@ import 'package:immich_mobile/providers/asset.provider.dart'; import 'package:immich_mobile/providers/authentication.provider.dart'; import 'package:immich_mobile/providers/backup/backup.provider.dart'; import 'package:immich_mobile/providers/server_info.provider.dart'; +import 'package:immich_mobile/utils/provider_utils.dart'; import 'package:immich_mobile/utils/version_compatibility.dart'; import 'package:immich_mobile/widgets/common/immich_logo.dart'; import 'package:immich_mobile/widgets/common/immich_title_text.dart'; @@ -186,6 +187,9 @@ class LoginForm extends HookConsumerWidget { // This will remove current cache asset state of previous user login. ref.read(assetProvider.notifier).clearAllAsset(); + // Invalidate all api repository provider instance to take into account new access token + invalidateAllApiRepositoryProviders(ref); + try { final isAuthenticated = await ref.read(authenticationProvider.notifier).login(