From 6f24535b798e2e7fc330b355ee50f65caad69c2c Mon Sep 17 00:00:00 2001 From: Hugh Daschbach Date: Fri, 15 Dec 2023 17:55:07 -0800 Subject: [PATCH] Auto logout on unrecoverable authentication error. When an unrecoverable authentication error occurs, automatically log the user out. This seems better than leaving the user wondering why the UI is unresponsive or why each track they try to play fails with a quickly disappearing toast. Unrecoverable authentication errors typically mean the server has timed out the session out or the session token has been deleted on the server. Tokens expire after 14 days without use. Part-of: --- app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt | 1 + app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt | 1 + 2 files changed, 2 insertions(+) diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt index 9f46206..8d22c71 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/Extensions.kt @@ -63,6 +63,7 @@ fun Request.authorize(context: Context, oAuth: OAuth): Request { Log.e("Request.authorize()", "performActionWithFreshToken failed: $e") if (e.type != 2 || e.code != 2002) { Log.e("Request.authorize()", Log.getStackTraceString(e)) + EventBus.send(Event.LogOut) } } if (token != old && token != null) { diff --git a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt index e36a0ea..c644d9f 100644 --- a/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt +++ b/app/src/main/java/audio/funkwhale/ffa/utils/OAuth.kt @@ -103,6 +103,7 @@ class OAuth(private val authorizationServiceFactory: AuthorizationServiceFactory if (e != null) { Log.e("OAuth", "performTokenRequest failed: $e") Log.e("OAuth", Log.getStackTraceString(e)) + EventBus.send(Event.LogOut) } else { state.apply { Log.i("OAuth", "applying new authState")