Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

262
Views
Keycloak-js refresh token in Vue.js 2 and Vuex

Hi everyone I have a problem with the keycloack refresh token and the keycloack-js v16.1.1 library, inside my application I have to make a page publicly accessible, to do everything I create the keycloak instance and assign this in a Vue plugin by myself created in authorization.js file:

// file authorization.js

const AuthPluginKeycloak = {
    install() {
        Vue.$keycloak = keycloak;
    }
}

AuthPluginKeycloak.install = Vue => {
    Vue.$keycloak = keycloak;
    Object.defineProperties(Vue.prototype, {
        $keycloak:{
            get() {
                return keycloak;
            }
        }
    })
}

I then had to move the library init from main to the login page. However, I left the refresh token inside the main.js with a setInterval of 170000 and set the update to 150 seconds considering that the token expires in 300s:

// main.js

setInterval(() => {
  Vue.$keycloak.updateToken(150)
      .then( async (refreshed) => {
         if (refreshed) {
         store.commit("updateIsLoggedIn", true);
         store.commit( "updateRefreshToken", this.$keycloak.refreshToken );
         store.commit( "updateToken", Vue.$keycloak.idToken );
         console.log('Token refreshed '+ refreshed);
         http.defaults.headers.common = { 'Authorization': `Bearer ${ await Vue.$keycloak.idToken }` }
         } else {
          console.warn('Token not refreshed, valid for '
          + Math.round(Vue.$keycloak.tokenParsed.exp + Vue.$keycloak.timeSkew - new Date().getTime() / 1000) + ' seconds');
                                    }
      }).catch(()=>{
          store.commit("updateIsLoggedIn", false);
          store.commit("updateOrganizationGuid", "");
          console.error('Failed to refresh token');
      });

}, 170000 );


everything works fine including the refresh token, until I do a reload of the page, at which point the refresh token doesn't work anymore, could you help me please? I don't know where to turn.

Thanks.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!