Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Created August 14, 2020 21:17
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/5804b5ef87feb3f76c7428a059ba5494 to your computer and use it in GitHub Desktop.
Save isaidspaghetti/5804b5ef87feb3f76c7428a059ba5494 to your computer and use it in GitHub Desktop.
//backend/routes/index.js:27
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 client = new StreamChat(streamApiKey, streamApiSecret);
[customer, admin] = createUsers(firstName, lastName);
await client.upsertUsers([
customer,
admin
]);
const channel = client.channel('messaging', uuidv4(), {
members: [customer.id, admin.id],
});
const customerToken = client.createToken(customer.id);
res.status(200).json({
customerId: customer.id,
customerToken,
channelId: channel.id,
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