Computes the absolute expiry time of a token response.
Combine this with refreshAccessToken to refresh proactively before the access token expires instead of waiting for a 401 from the API.
401
The token response to compute the expiry for.
The current time in milliseconds since the Unix epoch. Defaults to the time at which the helper is called.
The moment the access token expires.
const token = await getAccessToken("1234", "secret", "code-from-redirect");if (Date.now() >= getTokenExpiry(token).getTime() - 60_000) { const refreshed = await refreshAccessToken("1234", "secret", storedRefreshToken);} Copy
const token = await getAccessToken("1234", "secret", "code-from-redirect");if (Date.now() >= getTokenExpiry(token).getTime() - 60_000) { const refreshed = await refreshAccessToken("1234", "secret", storedRefreshToken);}
Computes the absolute expiry time of a token response.
Combine this with refreshAccessToken to refresh proactively before the access token expires instead of waiting for a
401from the API.