Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import dotenv from 'dotenv';
import md5 from 'md5';
import { StreamChat } from 'stream-chat';
exports.token = async (req, res) => {
try {
const data = req.body;
let apiKey;
let apiSecret;
if (process.env.STREAM_URL) {
[apiKey, apiSecret] = process.env.STREAM_URL.substr(8)
} else {
apiKey = process.env.STREAM_API_KEY;
apiSecret = process.env.STREAM_API_SECRET;
const client = new StreamChat(apiKey, apiSecret);
const user = Object.assign({}, data, {
id: md5(data.username),
role: 'admin',
image: `${data.username}`,
const token = client.createToken(;
await client.updateUsers([user]);
res.status(200).json({ user, token, apiKey });
} catch (error) {
res.status(500).json({ error: error.message });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.