Token handler.

Implement this handler to receive token events from the sdk and to handle backend token renewals. The instance can be set in ConnectOptions.

interface TokenHandler {
    onRenew(expiredAccessToken, refreshToken, renewed): void;
    onRenewed(newAccessToken, newRefreshToken): void;
}

Methods

  • Called when an access token is missing or expired that must be renewed via the backend.

    Parameters

    • expiredAccessToken: null | string

      The user's expired access token.

    • refreshToken: null | string

      The user's refresh token for the exired access token.

    • renewed: ((newAccessToken, newRefreshToken) => void)

      The completion handler to be called with the new access and refresh tokens on success or nil if it fails.

      This method will be called when an access token is missing or expired and needs renewing via the backend. The SDK will first attempt automatic renewal of tokens via the frontend, but if this fails because the refresh token is missing, revoked or of some other error, a backend renewal will be required. Backend renewals require proxying the request through your own backend api to Younify using your private api key. The renewed completion handler must be called with the new tokens or null if an error occurs. As a convenience, onRenewed will be called afterward on success to persist the new tokens in device storage.

        • (newAccessToken, newRefreshToken): void
        • Parameters

          • newAccessToken: null | string
          • newRefreshToken: null | string

          Returns void

    Returns void

  • Called when an access token and refresh token are renewed and need persisted.

    Parameters

    • newAccessToken: string

      The user's newly acquired access token.

    • newRefreshToken: string

      The user's newly acquired refresh token.

      This method will be called when an access token and refresh token have been renewed and need persisted. The listener should persisted the new tokens in device local storage in a non-cloud-sync'd manner. If the tokens are accidentally shared between multiple devices, frontend renewal on one device may cause the other devices to be logged out triggering a backend renewal request via onRenew.

    Returns void