Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keycloak.updateToken(50) The token is not refreshing the first time. #93

Open
RaviDhakadDoodle opened this issue May 17, 2022 · 1 comment

Comments

@RaviDhakadDoodle
Copy link

keycloak.updateToken(50)

I want to refresh the token every minute. So I have added code :-
keycloak.onTokenExpired = () => { keycloak.updateToken(50) .then((refreshed) => { if (refreshed && keycloak.token) { console.log('Token refreshed'); } }) .catch(() => { Alert. alert('Failed to refresh the token, or the session has expired.'); });

But it's not working as expected. For example, I have a token expiration time of 1 minute so it will call after 1 * 2 = 2 minutes only for the first time after that it works every minute.

To Reproduce

Expected behavior

Screenshots

Smartphone

  • Device:
  • OS:
  • Version

Additional context

@letiendungdn
Copy link

use in redux
const refreshToken = (state: any) => {
console.log('refresh token')
keycloak.init({
refreshToken: state.refreshToken,
token: state.token,
idToken: state.idToken,
redirectUri: 'demo-app://demo',
})
keycloak.onTokenExpired = () => {
keycloak
.updateToken(30)
.then(() => {
state.refreshToken = keycloak.refreshToken
state.token = keycloak.token
state.idToken = keycloak.idToken
console.log('successfully get a new token')
})
.catch(err => {
console.log(err)
})
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants