Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

bug: client.create_token returning a token but silently failing to create a user

未关闭
#133 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
ruby
领域
api, backend

调研方向

首先跟踪报告中提到的 Ruby 客户端入口点:client.create_token 和 channel.add_members,然后使用提供的 Ruby 示例重现这一序列。将 token 响应与后续的 channel 更新行为进行比较,并检查现有的客户端测试或请求处理;当创建用户流程及其失败行为与记录的 API 契约一致时,即表示完成。

由索引模型根据 Issue 内容生成。

描述

Describe the bug

I've got code which, on visiting the "messenger" page for the first time, attempts to create a user and add them to a default list of channels.
I create a token using client.create_token, then attempt to add the user to a few channels.

However, I'm getting the exception

StreamChat::StreamAPIException (StreamChat error code 4: UpdateChannel failed with error: "The following users are involved in channel update operation, but don't exist: [94461a35e0a73734438dba5ba10bbb74]. Please create the user objects before setting up the channel.")

client.create_token returns a 200 success and also returns a token.
The only exception I get is when I consequently try to add the user, using my manually generated user_id, to channels.

This was working yesterday - my code around user creation doesn't seem to have changed.

To Reproduce

  1. Create a user using client.create_token(id) (I'm using id = SecureRandom.hex(16))
  2. Attempt to add user using channel.add_members([id])

Expected behavior

The create_token endpoint should:

  1. create a user if params are valid (which in this case they are); AND
  2. return an error if params are invalid OR the server is experience issues, so error handling can be handled

Package version

stream-chat-react: 10.14.0
stream-chat-css: 3.13.0

Desktop (please complete the following information):

OS: MacOS Ventura 13.2
Browser: Chrome
Version: 118.0.5993.70

Additional context

require "securerandom"

class ChatsController < ApplicationController
  # ...

  def show
    # NOTE: I've checked this ENV vars are set correctly
    if (ENV["STREAM_API_KEY"] && ENV["STREAM_API_SECRET"]).present?
      if current_user.stream_user_id.nil?
        @stream_user_id = SecureRandom.hex(16)
        # NOTE: the line below fails silently
        @stream_user_token = StreamChatClient.create_stream_user(
          id: @stream_user_id
        )

        current_user.update!(
          stream_user_id: @stream_user_id,
          stream_user_token: @stream_user_token
        )
      else
        @stream_user_id = current_user.stream_user_id
        @stream_user_token = current_user.stream_user_token
      end

      add_current_user_to_channels
    else
      # ...
    end
  end

  private

  def add_current_user_to_channels
    [
      { type: "messaging", id: "general" },
      { type: "messaging", id: "feedback-and-requests" },
      { type: "messaging", id: "bugs" },
    ].each do |channel|
      channel = StreamChatClient.get_channel(
        type: channel[:type],
        channel_id: channel[:id],
      )
      unless StreamChatClient.channel_include?(
          channel: channel,
          user_id: current_user.stream_user_id
      )
        StreamChatClient.add_member(
          channel: channel,
          user_id: current_user.stream_user_id
        )
      end
    end
  end
end

My StreamChatClient class:

require "stream-chat"

class StreamChatClient
  def self.add_member(channel:, user_id:)
    channel.add_members([user_id])
  end

  def self.channel_include?(channel:, user_id:)
    members = channel.query_members()["members"]
    members.map{ |member| member["user_id"] }.include?(user_id)
  end

  def self.get_channel(type:, channel_id:)
    client.channel(type, channel_id: channel_id)
  end

  def self.create_stream_user(id:)
    client.create_token(id)
  end

  private

  def self.client
    StreamChat::Client.new(
      api_key=ENV["STREAM_API_KEY"],
      api_secret=ENV["STREAM_API_SECRET"]
    )
  end
end
主要语言
Ruby
星标
32
派生
23
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

GetStream/stream-chat-ruby 的其他 Issue

查看 GetStream/stream-chat-ruby 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。