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:
parent
9819b05e30
commit
a771f1e3bf
|
|
@ -1866,7 +1866,10 @@ class Client extends MatrixApi {
|
||||||
|
|
||||||
Future<void> _handleSoftLogout() async {
|
Future<void> _handleSoftLogout() async {
|
||||||
final onSoftLogout = this.onSoftLogout;
|
final onSoftLogout = this.onSoftLogout;
|
||||||
if (onSoftLogout == null) return;
|
if (onSoftLogout == null) {
|
||||||
|
await logout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_handleSoftLogoutFuture ??= () async {
|
_handleSoftLogoutFuture ??= () async {
|
||||||
onLoginStateChanged.add(LoginState.softLoggedOut);
|
onLoginStateChanged.add(LoginState.softLoggedOut);
|
||||||
|
|
@ -1875,7 +1878,7 @@ class Client extends MatrixApi {
|
||||||
onLoginStateChanged.add(LoginState.loggedIn);
|
onLoginStateChanged.add(LoginState.loggedIn);
|
||||||
} catch (e, s) {
|
} catch (e, s) {
|
||||||
Logs().w('Unable to refresh session after soft logout', e, s);
|
Logs().w('Unable to refresh session after soft logout', e, s);
|
||||||
await clear();
|
await logout();
|
||||||
rethrow;
|
rethrow;
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
@ -1991,10 +1994,10 @@ class Client extends MatrixApi {
|
||||||
onSyncStatus.add(SyncStatusUpdate(SyncStatus.error,
|
onSyncStatus.add(SyncStatusUpdate(SyncStatus.error,
|
||||||
error: SdkError(exception: e, stackTrace: s)));
|
error: SdkError(exception: e, stackTrace: s)));
|
||||||
if (e.error == MatrixError.M_UNKNOWN_TOKEN) {
|
if (e.error == MatrixError.M_UNKNOWN_TOKEN) {
|
||||||
final onSoftLogout = this.onSoftLogout;
|
if (e.raw.tryGet<bool>('soft_logout') == true) {
|
||||||
if (e.raw.tryGet<bool>('soft_logout') == true && onSoftLogout != null) {
|
Logs().w(
|
||||||
Logs().w('The user has been soft logged out! Try to login again...');
|
'The user has been soft logged out! Calling client.onSoftLogout() if present.',
|
||||||
|
);
|
||||||
await _handleSoftLogout();
|
await _handleSoftLogout();
|
||||||
} else {
|
} else {
|
||||||
Logs().w('The user has been logged out!');
|
Logs().w('The user has been logged out!');
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue