Skip to content

Commit

Permalink
Fix refresh token check
Browse files Browse the repository at this point in the history
  • Loading branch information
nonproto committed Oct 28, 2024
1 parent 3e0f16d commit 78babb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,21 @@ class MangaDexTokenAuthenticator(private val loginHelper: MangaDexLoginHelper) :
if (validated) {
TimberKt.i { "$tag Token is valid, other thread must have refreshed it" }
}
if (!validated) {
TimberKt.i { "$tag Token is invalid trying to refresh" }
validated = loginHelper.refreshSessionToken()
}

if (!validated) {
TimberKt.i { "$tag Unable to refresh token user will need to relogin" }
if (loginHelper.refreshToken().isNotBlank()) {
if (!validated) {
TimberKt.i { "$tag Token is invalid trying to refresh" }
validated = loginHelper.refreshSessionToken()
}

if (!validated) {
TimberKt.i { "$tag Unable to refresh token user will need to relogin" }
loginHelper.invalidate()
}
} else {
validated = false
loginHelper.invalidate()
}

loginHelper.sessionToken()

return@runBlocking when (validated) {
true -> "Bearer ${loginHelper.sessionToken()}"
false -> ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,8 @@ class MangaDexLoginHelper {
fun sessionToken(): String {
return preferences.sessionToken().get()
}

fun refreshToken(): String {
return preferences.refreshToken().get()
}
}

0 comments on commit 78babb7

Please sign in to comment.