KustomerCore.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 KustomerCore.login()
.
First, initialize chat
You must initialize with
KustomerCore.init()
before you can execute any additional Core SDK methods
Examples
// Login a customer
KustomerCore.login({
jwtToken: 'SOME_JWT_TOKEN'
});
// Login a customer and run a callback after the login
KustomerCore.login({
jwtToken: 'SOME_JWT_TOKEN'
}, function (loginCallbackResponse, error) {
if (!error) {
console.log('User was authenticated!');
}
});
Syntax
KustomerCore.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 KustomerCore.login() completes.callbackResponse is an object returned to the callback function. See the callbackResponse section below to see the properties of the object.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 Generate a JWT Token. To learn more about JSON Web Tokens, see https://jwt.io/. |
brandId | String | Optional You can override the default brand setting in your Kustomer Chat Settings by passing in a brandId .This is passed to init on a successful login |
assistantId | String | Optional By passing in an assistantId , you can override the default assistant setting in your Kustomer Chat Settings. This is passed to init on a successful login |
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 over 2 years ago