Auth0 Home Blog Docs

Is it possible to Renew tokens on page load?



I’m using the latest angular-auth0 & angular-jwt. I’m following the guides to setup my authentication flow and so far so good. I’m using passwordless email code authentication without Lock, so its included on my own page with custom design. Works with angularAuth0.passwordlessStart & passwordlessLogin.

By default the user is kept logged in for 2 hours, but i want to keep them signed in, especially because passwordless login is a bit slower compared to just entering the password. So i found the guide about renewing the tokens here:

My question is, based on the scheduleRenewal function, this will only run if i’m on the page, without closing it. If the token expired and i reload the page, i won’t get new tokens, since the renewToken function newer runs. Can i simply add the renewToken function in the else statement, so it tries to renew on page load if the token is expired? Like this:

  function scheduleRenewal() {
    var expiresAt = JSON.parse(localStorage.getItem('expires_at'));
    var delay = expiresAt -;
    if (delay > 0) {
      tokenRenewalTimeout = setTimeout(function() {
      }, delay);
    } else {

I looked through other examples of renewing the tokens, but all examples uses the code above, which doesn’t run on page load. Wondering whats the right solution in my case.



I tested the above method and it works, just wondering if might cause any issues in the future which is why it was left out from the examples.