【问题标题】:How retrieve session store from inside ActionCable::Connection::Base如何从 ActionCable::Connection::Base 内部检索会话存储
【发布时间】:2018-06-20 17:42:33
【问题描述】:

从动作电缆文档中,我阅读了这个设置 current_user 的示例:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

  def connect
    self.current_user = find_verified_user
  end

  private
    def find_verified_user
      if verified_user = User.find_by(id: cookies.signed[:user_id])
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

我没有设置 user_id cookie,因为身份验证是针对 cas 服务器进行的,并且它将会话存储在 Active Record 中。 如何告诉连接类当前用户?

【问题讨论】:

    标签: ruby-on-rails actioncable


    【解决方案1】:

    您需要强制加载会话。在此处查看此链接(为我工作):How force that session is loaded?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-10
      • 1970-01-01
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多