AccessTokenError when access token is not expired

It seems like, const { accessToken } = await getAccessToken() throws AccessTokenError saying that access token has been expired when it is actually NOT!

i’ve been trying to implement a feature with Nextjs14 where when access token expires, user is redirected to login page. I’ve tried setting session lifetime values described here but it never worked.

So i’m manually implementing the feature. I’m checking token expiary using this method

function isTokenExpired(expiresAt: number): boolean {
  if (!expiresAt) return true // returns true if expiresAt is undefined or 0

  const currentTime = Math.floor(Date.now() / 1000) // Convert to seconds
  
  return expiresAt <= currentTime
}

The issue is this:
when user still has about ~45seconds left til getting expired - according to the exp field embeded in accesstoken - getAccessToken function throws token expired error.
why is this the case?

Hi @shoh
Try passing the “refresh: true” option in your getAccessToken function call. Further try setting a rolling duration to > 1 day and see if that helps.