How to refresh access token for spa?

I’m loging in my Vue app like this:

var auth = new auth0.WebAuth({
   clientID: CLIENT_ID,
   domain: CLIENT_DOMAIN,
})

export function login() {
   auth.authorize({
      responseType: 'token id_token',
      redirectUri: REDIRECT,
      audience: AUDIENCE,
      scope: SCOPE,
   })
}

Everything works fine, but when token expires in 2 hours, I have to login again. I want to refresh token silently. How can i do it? I couldn’t find any “refresh_token”

Hi @DTX,

Welcome to the Auth0 Community Forum!

You should not use refresh tokens in a client side app (SPA). Take a look at silent authentication, if you are using auth0.js then you will use the checkSession method:

https://auth0.com/docs/api-auth/tutorials/silent-authentication#renew-expired-tokens

Hope this helps!

Thanks,
Dan

1 Like

Works like a charm! Thanks!

Btw before asking a question I checked like every method of the authjs instance except checkSession (:

It is not the most obvious name, although it makes sense when you dive into what it does. Glad it is working!

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.