Skip to content

Instantly share code, notes, and snippets.

@isaidspaghetti
Last active July 27, 2020 22:44
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/6607b462523a183e6ea5ca8839796afe to your computer and use it in GitHub Desktop.
Save isaidspaghetti/6607b462523a183e6ea5ca8839796afe to your computer and use it in GitHub Desktop.
Index registration
//backend/routes/index.js:46
router.post('/registrations', async (req, res) => {
try {
const firstName = req.body.firstName.replace(/\s/g, '_');
const lastName = req.body.lastName.replace(/\s/g, '_');
const email = req.body.email.toLowerCase();
const hubspotContactId = await createHubspotContact(firstName, lastName, email);
const client = new StreamChat(apiKey, apiSecret);
[customer, admin] = createUsers(firstName, lastName);
await client.upsertUsers([
customer,
admin
]);
const channel = client.channel('messaging', hubspotContactId, {
members: [customer.id, admin.id],
});
const customerToken = client.createToken(customer.id);
res.status(200).json({
customerId: customer.id,
customerToken,
channelId: channel.id,
apiKey,
});
} 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