Merge pull request #1895 from famedly/krille/call-logout-on-soft-logout-cancel

fix: Call logout on soft logout fail
This commit is contained in:
Krille-chan 2024-07-31 14:06:24 +02:00 committed by GitHub
commit 6dbc11180c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
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!');