login:
loginUser sends a POST request to the authentication endpoint and navigates to the chat page, passing the received token as a query parameter:
location.href = 'chat.html?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...';
registerUser sends a POST request to the users endpoint and calls the loginUser functionchat retrieve the authentication token from the query parameters:
const token = new URLSearchParams(location.search).get('token');
Use the token to implement the request functions:
fetchMessages sends a GET request to the messages endpoint and renders the recevied messagespostMessage sends a POST request to the messages endpointlogin page.
fetchMessages repeatedly (e.g. every 10 seconds) so that the chat messages are automatically refreshed.