mirror of
https://github.com/immich-app/immich.git
synced 2024-12-20 00:38:24 +02:00
bf3f4e560d
* chore(mobile): Improve reliability of asset loading and indexing * chore: add comments * chore: remove log * fix: put back box open sequence
33 lines
1.1 KiB
Dart
33 lines
1.1 KiB
Dart
import 'package:auto_route/auto_route.dart';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:hive/hive.dart';
|
|
import 'package:immich_mobile/constants/hive_box.dart';
|
|
import 'package:immich_mobile/routing/router.dart';
|
|
import 'package:immich_mobile/shared/services/api.service.dart';
|
|
|
|
class AuthGuard extends AutoRouteGuard {
|
|
final ApiService _apiService;
|
|
AuthGuard(this._apiService);
|
|
@override
|
|
void onNavigation(NavigationResolver resolver, StackRouter router) async {
|
|
try {
|
|
// temporary fix for race condition that the _apiService
|
|
// get called before accessToken is set
|
|
var userInfoHiveBox = await Hive.openBox(userInfoBox);
|
|
var accessToken = userInfoHiveBox.get(accessTokenKey);
|
|
_apiService.setAccessToken(accessToken);
|
|
var res = await _apiService.authenticationApi.validateAccessToken();
|
|
|
|
if (res != null && res.authStatus) {
|
|
resolver.next(true);
|
|
} else {
|
|
router.replaceAll([const LoginRoute()]);
|
|
}
|
|
} catch (e) {
|
|
debugPrint("Error [onNavigation] ${e.toString()}");
|
|
router.replaceAll([const LoginRoute()]);
|
|
return;
|
|
}
|
|
}
|
|
}
|