Kustomer.login()
Authenticates a customer and fetches their session data.
Guide: Authenticate chat π
Visit Authenticate chat to learn how to authenticate chat with a secure JWT token.
If you have embedded our chat widget behind a login, or if you want to allow users to see their past conversations from a different device, you can authenticate them with Kustomer.login()
.
Kustomer Chat must finish initializing fully with Kustomer.start()
before you can execute any additional Web SDK methods.
Tip: Call other methods inside the callback of Kustomer.start()
to ensure Kustomer Chat always completes initialization before the code tries to run other methods.
To learn more, see Troubleshooting: Kustomer method calls won't execute.
Examples
We're provided some examples of how you can call Kustomer.login()
:
// Login a customer
Kustomer.login({
jwtToken: 'SOME_JWT_TOKEN'
});
// Login a customer and run a callback after the login
Kustomer.login({
jwtToken: 'SOME_JWT_TOKEN'
}, function (loginCallbackResponse, error) {
if (!error) {
console.log('User was authenticated!');
}
});
Syntax
Kustomer.login(options, function(callbackResponse, error))
Parameter | Type | Description |
---|---|---|
options | Object | Required An object containing the secure JWT token to authenticate the user with. More information on the token is listed below. |
function(callbackResponse, error) | Function | Optional A callback that is run after callbackResponse is an object returned to the callback function. See the error is either undefined or a native JavaScript Error object. |
options
options
Property | Type | Description |
---|---|---|
jwtToken | String | Required This is a secure token that contains information about the user you want to authenticate. To learn about how to generate this token for Kustomer, see Authenticate chat, Step 3. Generate a JWT Token. To learn more about JSON Web Tokens, see https://jwt.io/. |
callbackResponse
callbackResponse
These are the fields that will be returned in the login callback response.
Key | Type | Description |
---|---|---|
identified | Boolean | Required This says whether or not the user was identified successfully. |
customerId | String | Required This is the customer's unique ID in Kustomer. |
String | Optional This is the customer's email address. | |
externalId | String | Optional This is the customer's unique external ID. |
Updated 15 days ago