@@ -126,27 +126,31 @@ async function init(config: VueKeycloakConfig, store: Reactive<VueKeycloakInstan
126126 }
127127
128128 keycloak . onAuthSuccess = function ( ) {
129- if ( ! autoRefreshToken ) {
130- return
129+ let updateTokenInterval : number | undefined ;
130+
131+ if ( autoRefreshToken ) {
132+ updateTokenInterval = setInterval (
133+ ( ) => {
134+ keycloak . updateToken ( 60 )
135+ . then ( ( updated : boolean ) => {
136+ if ( options . init ?. enableLogging ) {
137+ console . log ( `[vue-keycloak-js] Token ${ updated ? 'updated' : 'not updated' } ` )
138+ }
139+ } )
140+ . catch ( ( error : unknown ) => {
141+ if ( options . init ?. enableLogging ) {
142+ console . log ( `[vue-keycloak-js] Error while updating token: ${ error } ` )
143+ }
144+ keycloak . clearToken ( )
145+ } ) } ,
146+ updateInterval ?? 10000
147+ )
131148 }
132- const updateTokenInterval = setInterval (
133- ( ) => {
134- keycloak . updateToken ( 60 )
135- . then ( ( updated : boolean ) => {
136- if ( options . init ?. enableLogging ) {
137- console . log ( `[vue-keycloak-js] Token ${ updated ? 'updated' : 'not updated' } ` )
138- }
139- } )
140- . catch ( ( error : unknown ) => {
141- if ( options . init ?. enableLogging ) {
142- console . log ( `[vue-keycloak-js] Error while updating token: ${ error } ` )
143- }
144- keycloak . clearToken ( )
145- } ) } ,
146- updateInterval ?? 10000
147- )
149+
148150 store . logoutFn = ( ) => {
149- clearInterval ( updateTokenInterval )
151+ if ( updateTokenInterval ) {
152+ clearInterval ( updateTokenInterval )
153+ }
150154 return keycloak . logout ( options . logout )
151155 }
152156 }
@@ -258,3 +262,4 @@ export type {
258262 VueKeycloakConfig ,
259263 VueKeycloakTokenParsed
260264} from './types'
265+
0 commit comments