1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-24 10:37:28 +02:00
immich/mobile/lib/routing/auth_guard.dart

26 lines
777 B
Dart
Raw Normal View History

2022-02-03 18:06:44 +02:00
import 'package:auto_route/auto_route.dart';
import 'package:flutter/foundation.dart';
import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/shared/services/api.service.dart';
2022-02-03 18:06:44 +02:00
class AuthGuard extends AutoRouteGuard {
final ApiService _apiService;
AuthGuard(this._apiService);
2022-02-03 18:06:44 +02:00
@override
void onNavigation(NavigationResolver resolver, StackRouter router) async {
try {
var res = await _apiService.authenticationApi.validateAccessToken();
if (res != null && res.authStatus) {
2022-02-03 18:06:44 +02:00
resolver.next(true);
} else {
router.replaceAll([const LoginRoute()]);
2022-02-03 18:06:44 +02:00
}
} catch (e) {
debugPrint("Error [onNavigation] ${e.toString()}");
router.replaceAll([const LoginRoute()]);
return;
2022-02-03 18:06:44 +02:00
}
}
}