mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
Refactor mobile to use OpenApi generated SDK (#336)
This commit is contained in:
parent
d69470e207
commit
ae7e582ec8
276 changed files with 14513 additions and 3003 deletions
|
|
@ -1,21 +1,25 @@
|
|||
import 'dart:convert';
|
||||
|
||||
import 'package:auto_route/auto_route.dart';
|
||||
import 'package:immich_mobile/shared/services/network.service.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:immich_mobile/routing/router.dart';
|
||||
import 'package:immich_mobile/shared/services/api.service.dart';
|
||||
|
||||
class AuthGuard extends AutoRouteGuard {
|
||||
final NetworkService _networkService = NetworkService();
|
||||
|
||||
final ApiService _apiService;
|
||||
AuthGuard(this._apiService);
|
||||
@override
|
||||
void onNavigation(NavigationResolver resolver, StackRouter router) async {
|
||||
try {
|
||||
var res = await _networkService.postRequest(url: 'auth/validateToken');
|
||||
var jsonReponse = jsonDecode(res.toString());
|
||||
if (jsonReponse['authStatus']) {
|
||||
var res = await _apiService.authenticationApi.validateAccessToken();
|
||||
|
||||
if (res != null && res.authStatus) {
|
||||
resolver.next(true);
|
||||
} else {
|
||||
router.replaceAll([const LoginRoute()]);
|
||||
}
|
||||
} catch (e) {
|
||||
router.removeUntil((route) => route.name == "LoginRoute");
|
||||
debugPrint("Error [onNavigation] ${e.toString()}");
|
||||
router.replaceAll([const LoginRoute()]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue