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.
This commit is contained in:
Krille 2024-07-31 12:53:29 +02:00
parent 9819b05e30
commit a771f1e3bf
No known key found for this signature in database
GPG Key ID: E067ECD60F1A0652
1 changed files with 9 additions and 6 deletions

View File

@ -1866,7 +1866,10 @@ class Client extends MatrixApi {
Future<void> _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<bool>('soft_logout') == true && onSoftLogout != null) {
Logs().w('The user has been soft logged out! Try to login again...');
if (e.raw.tryGet<bool>('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!');