Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created August 19, 2020 23:43
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/d901443830ef67a71810ec3876639bdf to your computer and use it in GitHub Desktop.
Save isaidspaghetti/d901443830ef67a71810ec3876639bdf to your computer and use it in GitHub Desktop.
//backend/routes/index.js:10
router.post('/customer-login', async (req, res) => {
try {
const firstName = req.body.firstName.replace(/\s/g, '_');
const lastName = req.body.lastName.replace(/\s/g, '_');
const username = `${firstName}${lastName}`.toLowerCase();
const customerToken = serverSideClient.createToken(username);
await serverSideClient.updateUser(
{
id: username,
name: firstName
},
customerToken
);
const channel = serverSideClient.channel('messaging', username, {
name: `Chat with ${username}`,
created_by: { id: 'admin' },
members: [username, 'admin']
});
await channel.create();
await channel.addMembers([username, 'admin']);
res.status(200).json({
customerId: username,
channelId: username,
customerToken,
streamApiKey,
});
} catch (err) {
console.error(err);
res.status(500).json({ error: err.message });
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment