Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created August 14, 2020 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save isaidspaghetti/afe26e31ab03ef2bb3c41853e46a37f7 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/afe26e31ab03ef2bb3c41853e46a37f7 to your computer and use it in GitHub Desktop.
//frontend/src/App.js:14
const register = async (e) => {
try {
e.preventDefault();
const response = await fetch('http://localhost:8080/customer-login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
firstName,
lastName,
email,
}),
});
const { customerId, customerToken, channelId, streamApiKey } = await response.json();
const chatClient = new StreamChat(streamApiKey);
await chatClient.setUser(
{
id: customerId,
name: firstName,
},
customerToken,
);
const channel = chatClient.channel('messaging', channelId);
setChatClient(chatClient);
setChannel(channel);
} catch (e) {
console.error(e);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment