Last active
July 27, 2020 22:44
-
-
Save isaidspaghetti/6607b462523a183e6ea5ca8839796afe to your computer and use it in GitHub Desktop.
Index registration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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