Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getStreamClient() {
if (!process.env.STREAM_API_KEY) {
throw Error('Environment variable STREAM_API_KEY is not defined!');
}
if (!process.env.STREAM_API_SECRET) {
throw Error('Environment variable STREAM_API_SECRET is not defined!');
}
const client = new StreamChat(
process.env.STREAM_API_KEY,
process.env.STREAM_API_SECRET
);
return client;
}
async function chatAuth(ctx) {
try {
const { apiKey, apiSecret, apiBaseUrl } = await credentials(ctx);
const chatClient = new StreamChat(apiKey, apiSecret);
chatClient.setBaseURL(apiBaseUrl);
return chatClient;
} catch (error) {
ctx.error(
`Authentication required. Use the command ${chalk.green.bold(
'stream config:set'
)} to authenticate.`,
{
exit: 1,
}
);
}
}