Authenticate your Users
Your users must be authenticated to be able to participate in the Conversation. You perform this authentication using the Conversation ID and the JWTs you generated in a previous step.
Declare the following variables at the top of your chat.js file and populate ALICE_JWT, BOB_JWT and CONVERSATION_ID with your own values:
const ALICE_JWT = '';
const BOB_JWT = '';
const CONVERSATION_ID = '';
Here you will also get references to the other elements of the application and initialize some variables that will be used.
const aliceLoginBtn = document.getElementById("alice-login");
const bobLoginBtn = document.getElementById("bob-login");
const messageTextarea = document.getElementById("message-textarea");
const messageFeed = document.getElementById("message-feed");
const sendButton = document.getElementById("send");
let userToken;
let myMember;
You'll also need to add event listeners to the log in buttons for Alice and Bob so that userToken will be set with the selected user's JWT. The userToken with then be used in the run function. The run function doesn't do anything yet, but at this point you have a valid user JWT to start building your application.
aliceLoginBtn.addEventListener("click", () => {
userToken = ALICE_JWT;
run();
});
bobLoginBtn.addEventListener("click", () => {
userToken = BOB_JWT;
run();
});
Creating a web-based chat app
Create a web application that enables users to message each other