Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Call logout on soft logout fail #1895

Merged
merged 1 commit into from
Jul 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions lib/src/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}();
Expand Down Expand Up @@ -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!');
Expand Down
Loading