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))
ParameterTypeDescription
optionsObjectRequired

An object containing the secure JWT token to authenticate the user with. More information on the token is listed below.
function(callbackResponse, error)FunctionOptional

A callback that is run after Kustomer.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

PropertyTypeDescription
jwtTokenStringRequired

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

These are the fields that will be returned in the login callback response.

KeyTypeDescription
identifiedBooleanRequired

This says whether or not the user was identified successfully.
customerIdStringRequired

This is the customer's unique ID in Kustomer.
emailStringOptional

This is the customer's email address.
externalIdStringOptional

This is the customer's unique external ID.

What’s Next