Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

[auth] Allow local logout for custom endpoints

Neeraj Gupta8a540af278e6
diff --git a/mobile/packages/accounts/lib/services/user_service.dart b/mobile/packages/accounts/lib/services/user_service.dart
index e67dd877db..0fc95ec0f7 100644
--- a/mobile/packages/accounts/lib/services/user_service.dart
+++ b/mobile/packages/accounts/lib/services/user_service.dart
@@ -282,23 +282,28 @@ class UserService {
try {
final response = await _enteDio.post("/users/logout");
if (response.statusCode == 200) {
- await _config.logout();
- unawaited(
- Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false),
- );
+ await _logoutLocally(context);
} else {
throw Exception("Log out action failed");
}
} catch (e) {
- _logger.severe(e);
- // check if token is already invalid
- if (e is DioException && e.response?.statusCode == 401) {
- await _config.logout();
- unawaited(
- Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false),
- );
+ final bool shouldLogoutLocally =
+ (e is DioException && e.response?.statusCode == 401) ||
+ !_config.isEnteProduction();
+
+ if (shouldLogoutLocally) {
+ if (!_config.isEnteProduction()) {
+ _logger.info(
+ "Custom endpoint detected, proceeding with local logout despite server error",
+ );
+ } else {
+ _logger.info("Token already invalid, proceeding with local logout");
+ }
+ await _logoutLocally(context);
return;
}
+
+ _logger.severe(e);
//This future is for waiting for the dialog from which logout() is called
//to close and only then to show the error dialog.
Future.delayed(
@@ -309,6 +314,15 @@ class UserService {
}
}
+ Future<void> _logoutLocally(BuildContext context) async {
+ await _config.logout();
+ if (context.mounted) {
+ unawaited(
+ Navigator.of(context).pushNamedAndRemoveUntil('/', (route) => false),
+ );
+ }
+ }
+
Future<DeleteChallengeResponse?> getDeleteChallenge(
BuildContext context,
) async {