title: Checking token expiry on every request on the frontend
body: <p>I am using JWT's to authenticate my API server. The JWT is issued by an external auth server (in this case keycloak) and have a typical expiration time of ~5 minutes (IIRC), the frontend should then use these tokens to make requests to the API.</p>
  
  <p>I have been trying to check the expiry date of the token on the frontend, before making each request. If the token is expired, I use the refresh token to first get a new auth token then make the request.</p>
  
  <p>The basic workflow is:</p>
  
  <p>== Login ==
  1. Get Auth token
  2. Store expiry (exp) date (this is in UTC seconds)</p>
  
  <p>== API Request ==
  1. Check expiry date (<code>isExpired = expiryDate &lt;= Math.floor(Date.now() / 1000)</code>)
  2. If OK => make request
  3. Otherwise, refresh auth token and redo request.</p>
  
  <p>Is it bad practice to check the date like this? What is an alternative method to ensuring requests succeed?</p>
  
  <p>I ask because I have seen problems on some machines where the expiration check always returns <code>false</code> (it is not expired)...</p>