Skip to content

Commit

Permalink
chore: added some debug logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Jostein Tveit authored and josteitv committed Jun 7, 2023
1 parent 6925661 commit 660fc19
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,25 @@ function init(config: VueKeycloakConfig, watch: VueKeycloakInstance, options:Vue
}
keycloak.onAuthSuccess = function () {
// Check token validity every 10 seconds (10 000 ms) and, if necessary, update the token.
// Refresh token if it's valid for less then 60 seconds
// Refresh token if it's valid for less than 60 seconds
const updateTokenInterval = setInterval(
() =>
keycloak.updateToken(60).catch(() => {
keycloak.clearToken()
}),
() => {
keycloak.updateToken(60)
.then((updated) => {
if (options.init.enableLogging) {
if (updated) {
console.log('[vue-keycloak-js] Token updated')
} else {
console.log('[vue-keycloak-js] Token not updated')
}
}
})
.catch(error => {
if (options.init.enableLogging) {
console.log('[vue-keycloak-js] Error while updating token: ' + error)
}
keycloak.clearToken()
})},
updateInterval ?? 10000
)
watch.logoutFn = () => {
Expand Down

0 comments on commit 660fc19

Please sign in to comment.