Created
June 15, 2022 14:06
-
-
Save theanilpaudel/49e0d876ff06dff3855c0d03058e3dbf to your computer and use it in GitHub Desktop.
TokenAuthenticator for handling token expiry.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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