Skip to content

Commit

Permalink
there is no need to make SessionInterceptor.userId() suspendable
Browse files Browse the repository at this point in the history
  • Loading branch information
frett committed Oct 12, 2023
1 parent d3ec3f1 commit f214c3f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ abstract class AccountModule {
@ApplicationContext context: Context,
accountManager: GodToolsAccountManager
) = object : MobileContentApiSessionInterceptor(context) {
override suspend fun userId() = accountManager.userId
override fun userId() = accountManager.userId
override suspend fun authenticate() = accountManager.authenticateWithMobileContentApi()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import org.cru.godtools.api.model.AuthToken
private const val HTTP_HEADER_AUTHORIZATION = "Authorization"

abstract class MobileContentApiSessionInterceptor(context: Context) : SessionInterceptor<UserIdSession>(context) {
override fun loadSession(prefs: SharedPreferences) = runBlocking { userId()?.let { UserIdSession(prefs, it) } }
override fun loadSession(prefs: SharedPreferences) = userId()?.let { UserIdSession(prefs, it) }

override fun attachSession(request: Request, session: UserIdSession): Request {
if (!session.isValid) return request
Expand All @@ -31,6 +31,6 @@ abstract class MobileContentApiSessionInterceptor(context: Context) : SessionInt

override fun isSessionInvalid(response: Response) = response.code == HttpURLConnection.HTTP_UNAUTHORIZED

protected abstract suspend fun userId(): String?
protected abstract fun userId(): String?
protected abstract suspend fun authenticate(): AuthToken?
}

0 comments on commit f214c3f

Please sign in to comment.