You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-08-10 23:22:22 +02:00
fix(mobile): mobile logging out randomly (#11431)
* fix(mobile): refactor splash screen to not require online connection * chore: bump flutter sdk path for vscode * refactor: authentication provider always try network calls and only fail if 401 or no local user * lint * fix: revert change to lookup serverendpoint from store the isar store implementation is very broken * fix: clear serverUrl and serverEndpoint on logout, and await logout call * refactor: remove unneeded extra conditions in splash screen useEffect * revert change to remove serverEndpoint on logging out * pr feedback --------- Co-authored-by: Zack Pollard <zackpollard@ymail.com>
This commit is contained in:
@@ -9,7 +9,6 @@ import 'package:immich_mobile/routing/router.dart';
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/providers/api.provider.dart';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:openapi/api.dart';
|
||||
|
||||
@RoutePage()
|
||||
class SplashScreenPage extends HookConsumerWidget {
|
||||
@@ -19,45 +18,22 @@ class SplashScreenPage extends HookConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final apiService = ref.watch(apiServiceProvider);
|
||||
final serverUrl = Store.tryGet(StoreKey.serverUrl);
|
||||
final endpoint = Store.tryGet(StoreKey.serverEndpoint);
|
||||
final accessToken = Store.tryGet(StoreKey.accessToken);
|
||||
final log = Logger("SplashScreenPage");
|
||||
|
||||
void performLoggingIn() async {
|
||||
bool isSuccess = false;
|
||||
bool deviceIsOffline = false;
|
||||
bool isAuthSuccess = false;
|
||||
|
||||
if (accessToken != null && serverUrl != null) {
|
||||
try {
|
||||
// Resolve API server endpoint from user provided serverUrl
|
||||
await apiService.resolveAndSetEndpoint(serverUrl);
|
||||
} on ApiException catch (error, stackTrace) {
|
||||
log.severe(
|
||||
"Failed to resolve endpoint [ApiException]",
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
// okay, try to continue anyway if offline
|
||||
if (error.code == 503) {
|
||||
deviceIsOffline = true;
|
||||
log.warning("Device seems to be offline upon launch");
|
||||
} else {
|
||||
log.severe("Failed to resolve endpoint", error);
|
||||
}
|
||||
} catch (error, stackTrace) {
|
||||
log.severe(
|
||||
"Failed to resolve endpoint [Catch All]",
|
||||
error,
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
if (accessToken != null && serverUrl != null && endpoint != null) {
|
||||
apiService.setEndpoint(endpoint);
|
||||
|
||||
try {
|
||||
isSuccess = await ref
|
||||
isAuthSuccess = await ref
|
||||
.read(authenticationProvider.notifier)
|
||||
.setSuccessLoginInfo(
|
||||
accessToken: accessToken,
|
||||
serverUrl: serverUrl,
|
||||
offlineLogin: deviceIsOffline,
|
||||
);
|
||||
} catch (error, stackTrace) {
|
||||
log.severe(
|
||||
@@ -66,39 +42,35 @@ class SplashScreenPage extends HookConsumerWidget {
|
||||
stackTrace,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
isAuthSuccess = false;
|
||||
log.severe(
|
||||
'Missing authentication, server, or endpoint info from the local store',
|
||||
);
|
||||
}
|
||||
|
||||
// If the device is offline and there is a currentUser stored locallly
|
||||
// Proceed into the app
|
||||
if (deviceIsOffline && Store.tryGet(StoreKey.currentUser) != null) {
|
||||
context.replaceRoute(const TabControllerRoute());
|
||||
} else if (isSuccess) {
|
||||
// If device was able to login through the internet successfully
|
||||
final hasPermission =
|
||||
await ref.read(galleryPermissionNotifier.notifier).hasPermission;
|
||||
if (hasPermission) {
|
||||
// Resume backup (if enable) then navigate
|
||||
ref.watch(backupProvider.notifier).resumeBackup();
|
||||
}
|
||||
context.replaceRoute(const TabControllerRoute());
|
||||
} else {
|
||||
if (!isAuthSuccess) {
|
||||
log.severe(
|
||||
'Unable to login through offline or online methods - logging out completely',
|
||||
'Unable to login using 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());
|
||||
return;
|
||||
}
|
||||
|
||||
context.replaceRoute(const TabControllerRoute());
|
||||
|
||||
final hasPermission =
|
||||
await ref.read(galleryPermissionNotifier.notifier).hasPermission;
|
||||
if (hasPermission) {
|
||||
// Resume backup (if enable) then navigate
|
||||
ref.watch(backupProvider.notifier).resumeBackup();
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(
|
||||
() {
|
||||
if (serverUrl != null && accessToken != null) {
|
||||
performLoggingIn();
|
||||
} else {
|
||||
context.replaceRoute(const LoginRoute());
|
||||
}
|
||||
performLoggingIn();
|
||||
return null;
|
||||
},
|
||||
[],
|
||||
|
Reference in New Issue
Block a user