mirror of
https://github.com/immich-app/immich.git
synced 2026-04-24 18:19:51 -04:00
fix(mobile): clear local data on forced logout (#27957)
This commit is contained in:
parent
70397dc5a6
commit
3dc7dc93d8
@ -7,13 +7,15 @@ import 'package:immich_mobile/domain/services/store.service.dart';
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/routing/router.dart';
|
||||
import 'package:immich_mobile/services/api.service.dart';
|
||||
import 'package:immich_mobile/services/auth.service.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
class AuthGuard extends AutoRouteGuard {
|
||||
final ApiService _apiService;
|
||||
final AuthService _authService;
|
||||
final _log = Logger("AuthGuard");
|
||||
AuthGuard(this._apiService);
|
||||
AuthGuard(this._apiService, this._authService);
|
||||
@override
|
||||
void onNavigation(NavigationResolver resolver, StackRouter router) async {
|
||||
resolver.next(true);
|
||||
@ -27,7 +29,7 @@ class AuthGuard extends AutoRouteGuard {
|
||||
if (res == null || res.authStatus != true) {
|
||||
// If the access token is invalid, take user back to login
|
||||
_log.fine('User token is invalid. Redirecting to login');
|
||||
unawaited(router.replaceAll([const LoginRoute()]));
|
||||
unawaited(router.replaceAll([const LoginRoute()]).then((_) => _authService.clearLocalData()));
|
||||
}
|
||||
} on StoreKeyNotFoundException catch (_) {
|
||||
// If there is no access token, take us to the login page
|
||||
@ -38,7 +40,7 @@ class AuthGuard extends AutoRouteGuard {
|
||||
// On an unauthorized request, take us to the login page
|
||||
if (e.code == HttpStatus.unauthorized) {
|
||||
_log.warning("Unauthorized access token.");
|
||||
unawaited(router.replaceAll([const LoginRoute()]));
|
||||
unawaited(router.replaceAll([const LoginRoute()]).then((_) => _authService.clearLocalData()));
|
||||
return;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@ -73,6 +73,7 @@ import 'package:immich_mobile/routing/auth_guard.dart';
|
||||
import 'package:immich_mobile/routing/duplicate_guard.dart';
|
||||
import 'package:immich_mobile/routing/locked_guard.dart';
|
||||
import 'package:immich_mobile/services/api.service.dart';
|
||||
import 'package:immich_mobile/services/auth.service.dart';
|
||||
import 'package:immich_mobile/services/local_auth.service.dart';
|
||||
import 'package:immich_mobile/services/secure_storage.service.dart';
|
||||
import 'package:maplibre_gl/maplibre_gl.dart';
|
||||
@ -82,6 +83,7 @@ part 'router.gr.dart';
|
||||
final appRouterProvider = Provider(
|
||||
(ref) => AppRouter(
|
||||
ref.watch(apiServiceProvider),
|
||||
ref.watch(authServiceProvider),
|
||||
ref.watch(galleryPermissionNotifier.notifier),
|
||||
ref.watch(secureStorageServiceProvider),
|
||||
ref.watch(localAuthServiceProvider),
|
||||
@ -96,11 +98,12 @@ class AppRouter extends RootStackRouter {
|
||||
|
||||
AppRouter(
|
||||
ApiService apiService,
|
||||
AuthService authService,
|
||||
GalleryPermissionNotifier galleryPermissionNotifier,
|
||||
SecureStorageService secureStorageService,
|
||||
LocalAuthService localAuthService,
|
||||
) {
|
||||
_authGuard = AuthGuard(apiService);
|
||||
_authGuard = AuthGuard(apiService, authService);
|
||||
_duplicateGuard = const DuplicateGuard();
|
||||
_lockedGuard = LockedGuard(apiService, secureStorageService, localAuthService);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user