AniLink - v2.0.0
    Preparing search index...

    Function getTokenExpiry

    • 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.

      Parameters

      • response: AniListTokenResponse

        The token response to compute the expiry for.

      • now: number = ...

        The current time in milliseconds since the Unix epoch. Defaults to the time at which the helper is called.

      Returns Date

      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);
      }