mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
fix(mobile): ios random logout (#8997)
* fix(mobile): random logout * move logout mechanism to the end * More logs * wording * more logs * fixed * Better check
This commit is contained in:
parent
70c78a09a4
commit
48b0b7e8bd
6 changed files with 70 additions and 25 deletions
|
|
@ -7,6 +7,7 @@ import 'package:immich_mobile/shared/services/server_info.service.dart';
|
|||
import 'package:immich_mobile/shared/models/server_info/server_config.model.dart';
|
||||
import 'package:immich_mobile/shared/models/server_info/server_features.model.dart';
|
||||
import 'package:immich_mobile/shared/models/server_info/server_version.model.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
|
||||
class ServerInfoNotifier extends StateNotifier<ServerInfo> {
|
||||
|
|
@ -47,6 +48,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
|
|||
);
|
||||
|
||||
final ServerInfoService _serverInfoService;
|
||||
final _log = Logger("ServerInfoNotifier");
|
||||
|
||||
Future<void> getServerInfo() async {
|
||||
await getServerVersion();
|
||||
|
|
@ -55,17 +57,25 @@ class ServerInfoNotifier extends StateNotifier<ServerInfo> {
|
|||
}
|
||||
|
||||
getServerVersion() async {
|
||||
final serverVersion = await _serverInfoService.getServerVersion();
|
||||
try {
|
||||
final serverVersion = await _serverInfoService.getServerVersion();
|
||||
|
||||
if (serverVersion == null) {
|
||||
if (serverVersion == null) {
|
||||
state = state.copyWith(
|
||||
isVersionMismatch: true,
|
||||
versionMismatchErrorMessage: "common_server_error".tr(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await _checkServerVersionMismatch(serverVersion);
|
||||
} catch (e, stackTrace) {
|
||||
_log.severe("Failed to get server version", e, stackTrace);
|
||||
state = state.copyWith(
|
||||
isVersionMismatch: true,
|
||||
versionMismatchErrorMessage: "common_server_error".tr(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
await _checkServerVersionMismatch(serverVersion);
|
||||
}
|
||||
|
||||
_checkServerVersionMismatch(ServerVersion serverVersion) async {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import 'dart:io';
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:immich_mobile/shared/models/store.dart';
|
||||
import 'package:immich_mobile/utils/url_helper.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
import 'package:http/http.dart';
|
||||
|
||||
|
|
@ -34,6 +35,7 @@ class ApiService {
|
|||
}
|
||||
}
|
||||
String? _accessToken;
|
||||
final _log = Logger("ApiService");
|
||||
|
||||
setEndpoint(String endpoint) {
|
||||
_apiClient = ApiClient(basePath: endpoint);
|
||||
|
|
@ -95,14 +97,17 @@ class ApiService {
|
|||
serverUrl += '/api';
|
||||
}
|
||||
|
||||
// Throw Socket or Timeout exceptions,
|
||||
// we do not care if the endpoints hits an HTTP error
|
||||
try {
|
||||
await client
|
||||
.get(
|
||||
Uri.parse(serverUrl),
|
||||
)
|
||||
final response = await client
|
||||
.get(Uri.parse("$serverUrl/server-info/ping"))
|
||||
.timeout(const Duration(seconds: 5));
|
||||
|
||||
if (response.statusCode != 200) {
|
||||
_log.severe(
|
||||
"Server Gateway Error: ${response.body} - Cannot communicate to the server",
|
||||
);
|
||||
return false;
|
||||
}
|
||||
} on TimeoutException catch (_) {
|
||||
return false;
|
||||
} on SocketException catch (_) {
|
||||
|
|
|
|||
|
|
@ -25,20 +25,30 @@ class SplashScreenPage extends HookConsumerWidget {
|
|||
void performLoggingIn() async {
|
||||
bool isSuccess = false;
|
||||
bool deviceIsOffline = false;
|
||||
|
||||
if (accessToken != null && serverUrl != null) {
|
||||
try {
|
||||
// Resolve API server endpoint from user provided serverUrl
|
||||
await apiService.resolveAndSetEndpoint(serverUrl);
|
||||
} on ApiException catch (e) {
|
||||
} on ApiException catch (error, stackTrace) {
|
||||
log.severe(
|
||||
"Failed to resolve endpoint [ApiException]",
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
// okay, try to continue anyway if offline
|
||||
if (e.code == 503) {
|
||||
if (error.code == 503) {
|
||||
deviceIsOffline = true;
|
||||
log.fine("Device seems to be offline upon launch");
|
||||
log.warning("Device seems to be offline upon launch");
|
||||
} else {
|
||||
log.severe("Failed to resolve endpoint", e);
|
||||
log.severe("Failed to resolve endpoint", error);
|
||||
}
|
||||
} catch (e) {
|
||||
log.severe("Failed to resolve endpoint", e);
|
||||
} catch (error, stackTrace) {
|
||||
log.severe(
|
||||
"Failed to resolve endpoint [Catch All]",
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
@ -50,15 +60,11 @@ class SplashScreenPage extends HookConsumerWidget {
|
|||
offlineLogin: deviceIsOffline,
|
||||
);
|
||||
} catch (error, stackTrace) {
|
||||
ref.read(authenticationProvider.notifier).logout();
|
||||
|
||||
log.severe(
|
||||
'Cannot set success login info',
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
|
||||
context.pushRoute(const LoginRoute());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,6 +82,11 @@ class SplashScreenPage extends HookConsumerWidget {
|
|||
}
|
||||
context.replaceRoute(const TabControllerRoute());
|
||||
} else {
|
||||
log.severe(
|
||||
'Unable to login through offline or online methods - logging out completely',
|
||||
);
|
||||
|
||||
ref.read(authenticationProvider.notifier).logout();
|
||||
// User was unable to login through either offline or online methods
|
||||
context.replaceRoute(const LoginRoute());
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue