Types
AuthInfo
The authentication information of a user.Properties
Name | Type | Description |
---|---|---|
token | string | The User Info Token. |
orgID | string | The user’s organization ID. |
userID | string | The user ID. |
(Optional) action | string | The current operation type. You can ignore this parameter. |
MfaListItem
The information about a multi-factor authentication (MFA) method that will be displayed in the UI.Properties
Name | Type | Description |
---|---|---|
mfaMethod | string | The MFA method type. The possible values are as follows:
|
mfaStatus | string | The active status of the MFA method. The possible values are as follows:
Inactive . |
Enums
locale
The language setting.en-US
: English.zh-CN
: Chinese.
Hooks
useMFA
Returns
This hook returns a functionsendMfaMethods
that sends an array of MFA methods to Cobo’s backend.
The sendMfaMethods
function has the following parameter:
Name | Type | Description |
---|---|---|
mfaMethods | MfaListItem [] | An array of MfaListItem objects. Each object represents an MFA method that will be displayed in the UI. |
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 usingsendMfaMethods
, and handles the response or any errors.
useTrackingScript
Parameters
Name | Type | Description |
---|---|---|
env | string | The type of environment in which your app runs. For more details, refer to environments. Currently, this parameter value must be production , regardless of whether your app runs in the production environment or development environment. |
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 nameddata-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
, andprofile
. - 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
, andlink
. - Element identifier: Identifies the button or interactive element, including
submit
,register
, andnext_step
.
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:
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.
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.
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
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
Name | Type | Description |
---|---|---|
userId | string | The user ID to be added to the <body> tag. |
Sample code
The following example uses theuseAddUidToBody
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
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 thegetAuthInfo
function when the component mounts and displays that information.
parseJwtToken
Parameters
Name | Type | Description |
---|---|---|
token | string | The JWT string to be parsed. It must be in the header.payload.signature format. |
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 theparseJwtToken
function to parse a User Info Token and logs the decoded payload to the console.
verifyJwtToken
Parameters
Name | Type | Description |
---|---|---|
token | string | The JWT to be verified. It must be in the header.payload.signature format . |
publicKeySet | any | A set of public keys used to verify the JWT signature. Each public key should have a kid attribute, which matches the kid attribute in the JWT header. |
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
Call removeGetLocaleListener to clean up the listener when it is no longer needed, especially in components that may unmount.
Parameters
Name | Type | Description |
---|---|---|
callback | function | A function that takes a locale object as an argument. |
Returns
void
Errors
Failed to get locale
: The locale data is undefined.