Hey everyone, I’m having trouble with my chat app. I’m using Fastify for the backend and Stream Chat Server SDK version 8. When I try to sign up new users, I keep getting this error:
Error: Both secret and user tokens are not set. Either client.connectUser wasn't called or client.disconnect was called
I’ve set up my environment with the right API keys and I’m using streamChat.getInstance()
to create the client. Here’s a bit of my code:
const chatClient = ChatServer.init('my_api_key', 'my_secret_key');
app.post('/signup', async (req, res) => {
const { userId, userName } = req.body;
await chatClient.createUser({ id: userId, name: userName });
const userToken = chatClient.createToken(userId);
res.send({ token: userToken });
});
I’m not using connectUser()
on the server side because I thought that was just for the client SDK. Am I missing something? I’ve tried updating packages, double-checking my keys, and restarting the server, but no luck.
Any ideas what could be causing this? Thanks in advance!
I encountered a similar issue when upgrading to Stream Chat Server SDK v8. The problem lies in how the client is initialized. In v8, you need to use the StreamChat.getInstance()
method instead of ChatServer.init()
. Here’s the corrected code:
const StreamChat = require('stream-chat').StreamChat;
const serverClient = StreamChat.getInstance('your_api_key', 'your_api_secret');
app.post('/signup', async (req, res) => {
const { userId, userName } = req.body;
await serverClient.upsertUser({ id: userId, name: userName });
const token = serverClient.createToken(userId);
res.send({ token });
});
Note that createUser
is replaced with upsertUser
in v8. This should resolve the ‘Both secret and user tokens are not set’ error. Make sure to update your dependencies and double-check your API key and secret.
heya! have u tried checkin ur API key n secret? sometimes they can expire or get revoked. also, make sure ur not accidentally using the client SDK on the server. oh, and double-check ur Stream Chat version - v8 has some quirks. maybe try loggin the chatClient object to see if it’s initializing properly? just a thought!
hey mate, i had similar issue. make sure ur using the right version of stream-chat-server. v8 needs different setup. try this:
const StreamChat = require(‘stream-chat’).StreamChat;
const serverClient = StreamChat.getInstance(‘api_key’, ‘api_secret’);
that should fix it. let me kno if it works!