GetStream / stream-chat-js

JS / Browser Client - Build Chat with GetStream.io
https://getstream.io/chat/
Other
183 stars 76 forks source link

Cannot create a channel from the server client #1374

Closed jirom closed 1 month ago

jirom commented 1 month ago

I'm trying to create a channel on the server side but it's failing with the following error.

Error: StreamChat error code 4: GetOrCreateChannel failed with error: \"either data.created_by or data.created_by_id must be provided when using server side auth.\"

This is how I'm creating the channel.

const channel = client.channel("messaging", channelId, { name: chatname })
await channel.create()

According to the docs here I'm supposed to pass the creator as part of the custom object but the ChannelData type does not have a created_by_id field.

I'm currently depending on stream-chat: 8.40.9

szuperaz commented 1 month ago

Hi,

Indeed, our typings don't contain created_by_id. This is because the ChannelData is different if you connect client-side or server-side. However, the code in our documentation is correct, this is how you can provide the creator:

const channel = client.channel("messaging", channelId, { name: chatname, created_by_id: "<user id>" })
await channel.create()

Moving forward, we will have a separate Node SDK with proper server-side types, but until then, these typing inconsistencies can occur.

I'm going to close this ticket, but feel free to reopen it in case the solution doesn't work for you.