Login Visitor

Using the following method, you can load the conversation history of authenticated visitors (visitors who have logged in to your system). To do this, first get the user ID using the getVisitorId function and then save it in your database.

And then on your login page using JWT (HS256) encryption method and with the authentication key that you can copy from this page, encrypt the user ID as below

User authentication key is a private key, please do not share it with third parties and be sure to implement the following process on the back-end of your service

const jwt = require('jsonwebtoken');
const contact_hash = jwt.sign({contactId: visitorId}, identityVerificationKey);

Then send the encrypted value (contact_hash) to your client and load the desired visitor using the following code before loading the imber widget.

<script>
window.IMBER_AUTH = {
    contact_id: visitorId,
    contact_hash: contact_hash
};
</script>

Note that for ease in the process of loading the visitor history of the conversation after encryption and generation of the hash, Set into client-side storage like localStorage or cookies and use it with every refresh.

Last updated