From a771f1e3bfabe0eebe36103d22c976cd826515ff Mon Sep 17 00:00:00 2001 From: Krille Date: Wed, 31 Jul 2024 12:53:29 +0200 Subject: [PATCH] fix: Call logout on soft logout fail If we fail to handle the soft logout, we should call the logout endpoint to delete the device from the server instead of just clear the client. --- lib/src/client.dart | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/src/client.dart b/lib/src/client.dart index 84279fdd..41875642 100644 --- a/lib/src/client.dart +++ b/lib/src/client.dart @@ -1866,7 +1866,10 @@ class Client extends MatrixApi { Future _handleSoftLogout() async { final onSoftLogout = this.onSoftLogout; - if (onSoftLogout == null) return; + if (onSoftLogout == null) { + await logout(); + return; + } _handleSoftLogoutFuture ??= () async { onLoginStateChanged.add(LoginState.softLoggedOut); @@ -1875,7 +1878,7 @@ class Client extends MatrixApi { onLoginStateChanged.add(LoginState.loggedIn); } catch (e, s) { Logs().w('Unable to refresh session after soft logout', e, s); - await clear(); + await logout(); rethrow; } }(); @@ -1991,10 +1994,10 @@ class Client extends MatrixApi { onSyncStatus.add(SyncStatusUpdate(SyncStatus.error, error: SdkError(exception: e, stackTrace: s))); if (e.error == MatrixError.M_UNKNOWN_TOKEN) { - final onSoftLogout = this.onSoftLogout; - if (e.raw.tryGet('soft_logout') == true && onSoftLogout != null) { - Logs().w('The user has been soft logged out! Try to login again...'); - + if (e.raw.tryGet('soft_logout') == true) { + Logs().w( + 'The user has been soft logged out! Calling client.onSoftLogout() if present.', + ); await _handleSoftLogout(); } else { Logs().w('The user has been logged out!');