How is it possible to recall `loadTokens` again af...
# ktor
h
How is it possible to recall
loadTokens
again after the user logs in successfully in Bearer Authentication? Normally when the user opens the app the loadTokens will be triggered and because there is no saved access token it returns
BearerTokens(null, null)
. After the user logs in I save the access and refresh token in the database but loadTokens won’t be triggered again to set new access and refresh token. How can I force the Ktor to trigger
loadTokens
again after the user logs in?
Copy code
install(Auth) {
    bearer {
        loadTokens {
            // Some code to retrieve access and refresh token from the database
            BearerTokens(accessToken, refreshToken)
        }
    }
}
r
loadTokens
block should return
null
where there is no valid token
h
Ok, I changed my code to return null in case there in no saved access token but it still does not trigger loadTokens on every request to check if there is any new access and refresh tokens.
r
then you can use this code after you save your tokens
client.plugin(Auth).providers.filterIsInstance<BearerAuthProvider>().first().clearToken()
it’s ugly, but should work
🙏 1
h
It works even though it’s not that nice 😄 Thank you bro
Should I use this code after updating access token using refresh token?
r
no, it should update automatically
👍 1
100 Views