Skip to main content

Types

AuthInfo

The authentication information of a user.

Properties

MfaListItem

The information about a multi-factor authentication (MFA) method that will be displayed in the UI.

Properties

Enums

locale

The language setting.
  • en-US: English.
  • zh-CN: Chinese.

Hooks

useMFA

This hook manages multi-factor authentication (MFA) methods within your application. It provides a function to send MFA method data to Cobo for processing.

Returns

This hook returns a function sendMfaMethods that sends an array of MFA methods to Cobo’s backend. The sendMfaMethodsfunction has the following parameter: The sendMfaMethods function returns a Promise that resolves to a request ID of string type, which should be sent to Cobo Portal for processing.

Sample code

The following example defines an array of MFA methods, sends them using sendMfaMethods, and handles the response or any errors.

useTrackingScript

This hook injects a tracking script into the DOM, which collects data for app analytics, and ensures proper cleanup when the component unmounts. This data will be accessible on Developer Console in the future.

Parameters

Sample code

The following example loads a tracking script in both the production and development environments.

Notes

To enable effective tracking, each clickable element in your app needs a unique tracking attribute named data-track-id or dtid. This attribute serves as the primary identifier for tracking interactions on specific buttons or elements, enabling consistent and accurate analytics collection. Each data-track-id or dtid attribute value must be lowercase words separated by underscores in the format {PAGE_IDENTIFIER}_{COMPONENT_IDENTIFIER}_{ELEMENT_IDENTIFIER} that follow the following rules:
  • Page identifier: Identifying the page or module’s feature, including home, login, and profile.
  • Component identifier: Identifies the specific UI component within the page, including form, navbar, modal, search_bar, button, banner, icon_button, tab, switch_button, checkbox, radio, sidebar, footer, header, and link.
  • Element identifier: Identifies the button or interactive element, including submit, register, and next_step.
For example, the attribute value for a submit button on the home page can be home_form_submit. When an element contains child elements, avoid using event-blocking methods such as stopPropagation() and preventDefault() because they can interfere with effective click tracking. In typical cases, you only need to apply the data-track-id or dtid attribute to the parent element, as child elements will automatically inherit it for tracking purposes. The following example shows how to implement this:
However, if using the event-blocking methods is necessary, ensure that each child element within the parent has the same tracking attribute to maintain accurate tracking. Input field collection rules For input fields with a data-track-id, the user input and the value of data-track-id will be collected for analyzing user behavior. In the following example, the keywords entered by the user and the value of home_search_bar_wallet will be collected.
For sensitive information such as passwords and personal identification information, you can mark an input field as containing sensitive information by using data-track-sensitive="true", which will tell the tracking script to automatically ignore the data and not collect it. In the following example, the password entered by the user will not be collected by the tracking script.
If an input field is nested within other components (such as a form), the parent data-track-id will not override or replace the input field’s own data-track-id. In the following example, the data-track-id of the input field is login_form_email, not login_form.

useAddUidToBody

This hook converts a specified user ID from string to Base64 format and adds it as a uid attribute to the <body> tag of the HTML document. It is useful in scenarios where a user ID needs to be incorporated into the document structure for global tracking or analytics.

Parameters

Sample code

The following example uses the useAddUidToBody function to add a uid attribute to the <body> tag with the user ID. When the user ID changes, the value of the uid attribute is updated accordingly.

Functions

getAuthInfo

This asynchronous function retrieves user authentication information from Cobo Portal.

Returns

  • Promise<[AuthInfo]>: For more details, refer to AuthInfo.
  • undefined: The authentication information is unavailable or the request fails.

Sample code

The following example retrieves user authentication information using the getAuthInfo function when the component mounts and displays that information.

parseJwtToken

This function parses a JSON Web Token (JWT) and returns the payload as a JSON object. Use this function to extract user information, permissions, and other related information in a JWT. You can use this function to parse the User Info Token, which contains the information of a Cobo Portal App user.

Parameters

Returns

If the token is a valid JWT, the function returns the payload as a JSON object.

Errors

If the token format is incorrect or cannot be parsed, the function throws an error with messages such as:
  • Invalid Base64 encoding: The payload part of the token is not properly Base64 encoded.
  • Invalid token format: There is an issue parsing the token, for example, incorrect structure or failure to decode.

Sample code

The following example uses the parseJwtToken function to parse a User Info Token and logs the decoded payload to the console.

verifyJwtToken

This function verifies a JSON Web Token (JWT) using the specified public keys, ensuring that the token has not been tampered with and is valid. You can use this function to verify a Cobo Portal App user’s identity. Refer to User Info Tokens for more information.

Parameters

Returns

  • true: The JWT is valid.
  • false: The JWT is invalid.

Sample code

The following example verifies a User Info Token with the public key set retrieved from the specified URL. If the verification is successful, it extracts the information from the User Info Token and sets the information as the user’s information.

getPortalLocale

This function listens for the current locale data of Cobo Portal and executes a callback when the locale data updates.
Call removeGetLocaleListener to clean up the listener when it is no longer needed, especially in components that may unmount.

Parameters

Returns

void

Errors

Failed to get locale: The locale data is undefined.

Sample code

The following example listens for the locale data of Cobo Portal and logs it to the console when the data updates.

removeGetLocaleListener

This function removes the listener for the current locale data of Cobo Portal. After you call getPortalLocale to listen to the locale data, use this function to clean up the listener when it is no longer needed, especially in components that may unmount.