react-native-keycloak icon indicating copy to clipboard operation
react-native-keycloak copied to clipboard

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

Open RaviDhakadDoodle opened this issue 3 years ago • 1 comments
trafficstars

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

RaviDhakadDoodle avatar May 17 '22 10:05 RaviDhakadDoodle

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) }) } }

letiendungdn avatar May 25 '22 08:05 letiendungdn