Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created August 19, 2020 23:48
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/7595ae74d05153bdedac77883444c920 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/7595ae74d05153bdedac77883444c920 to your computer and use it in GitHub Desktop.
//frontend/src/Admin.js:23
const register = async (e) => {
try {
e.preventDefault();
const response = await fetch('http://localhost:8080/admin-login', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
adminId,
}),
});
const { adminToken, streamApiKey, adminName } = await response.json();
chatClient = new StreamChat(streamApiKey);
await chatClient.setUser(
{
id: adminName,
name: 'Administrator'
},
adminToken,
);
const channel = chatClient.channel('messaging', 'livechat');
await channel.watch();
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