Skip to content

Instantly share code, notes, and snippets.

@nparsons08 nparsons08/auth-token.js Secret
Created Nov 11, 2019

Embed
What would you like to do?
// backend/src/controllers/v1/stream-credentials.js
import { chat } from '../../stream';
exports.streamCredentials = async (req, res) => {
try {
const data = req.body;
const user = Object.assign({}, data, {
id: req.user.sender,
role: 'user',
image: `https://robohash.org/${req.user.sender}`,
});
const token = chat.createToken(user.id);
await chat.updateUsers([user]);
res.status(200).json({ user, token, apiKey: process.env.STREAM_API_KEY });
} catch (error) {
console.log(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.