mirror of
https://github.com/sudoxnym/audiobookshelf-atv.git
synced 2026-04-14 19:46:30 +00:00
Handle native app token refresh failure notification
This commit is contained in:
parent
b06274866d
commit
fab94cd363
4 changed files with 21 additions and 4 deletions
|
|
@ -126,8 +126,8 @@ class AbsDatabase : Plugin() {
|
|||
val userId = serverConfigPayload.userId
|
||||
val username = serverConfigPayload.username
|
||||
val serverVersion = serverConfigPayload.version
|
||||
val accessToken = serverConfigPayload.token // New token
|
||||
val refreshToken = serverConfigPayload.refreshToken // Refresh only sent on first connection
|
||||
val accessToken = serverConfigPayload.token
|
||||
val refreshToken = serverConfigPayload.refreshToken // Refresh only sent after login or refresh
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
if (serverConnectionConfig == null) { // New Server Connection
|
||||
|
|
|
|||
|
|
@ -404,7 +404,14 @@ class ApiHandler(var ctx:Context) {
|
|||
errorObj.put("error", "Authentication failed - please login again")
|
||||
callback(errorObj)
|
||||
|
||||
// TODO: Notify webview frontend
|
||||
if (checkAbsDatabaseNotifyListenersInitted()) {
|
||||
val tokenJsObject = JSObject()
|
||||
tokenJsObject.put("error", "Token refresh failed")
|
||||
absDatabaseNotifyListeners("onTokenRefreshFailure", tokenJsObject)
|
||||
} else {
|
||||
// Can happen if Webview is never run
|
||||
Log.i(tag, "AbsDatabaseNotifyListeners is not initialized so cannot send token refresh failure notification")
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(tag, "handleRefreshFailure: Error during failure handling", e)
|
||||
val errorObj = JSObject()
|
||||
|
|
|
|||
|
|
@ -131,4 +131,14 @@ export default ({ app, store }, inject) => {
|
|||
console.log('[db] onTokenRefresh', data)
|
||||
store.commit('user/setAccessToken', data.accessToken)
|
||||
})
|
||||
|
||||
// Listen for token refresh failure events from native app
|
||||
AbsDatabase.addListener('onTokenRefreshFailure', async (data) => {
|
||||
console.log('[db] onTokenRefreshFailure', data)
|
||||
// Clear store and redirect to login page
|
||||
await store.dispatch('user/logout')
|
||||
if (window.location.pathname !== '/connect') {
|
||||
window.location.href = '/connect'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ export default function ({ store, $db }, inject) {
|
|||
try {
|
||||
console.log('[nativeHttp] Handling refresh failure - logging out user')
|
||||
|
||||
// Logout from server and clear store
|
||||
// Clear store
|
||||
await store.dispatch('user/logout')
|
||||
|
||||
if (serverConnectionConfigId) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue