Created
August 14, 2020 21:17
-
-
Save isaidspaghetti/5804b5ef87feb3f76c7428a059ba5494 to your computer and use it in GitHub Desktop.
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: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