Skip to content

Instantly share code, notes, and snippets.

@theanilpaudel
Created June 15, 2022 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theanilpaudel/49e0d876ff06dff3855c0d03058e3dbf to your computer and use it in GitHub Desktop.
Save theanilpaudel/49e0d876ff06dff3855c0d03058e3dbf to your computer and use it in GitHub Desktop.
TokenAuthenticator for handling token expiry.
@Singleton
class TokenAutheticator @Inject constructor(
@ApplicationContext private val context: Context
) : Authenticator {
override fun authenticate(route: Route?, response: Response): Request? {
if (!response.isSuccessful) {
val localBroadcastManager = LocalBroadcastManager.getInstance(context)
val intent = Intent(Keys.ACTION_LOGOUT)
localBroadcastManager.sendBroadcast(intent)
return null
}
return response.request.newBuilder().build()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment