2016-03-08 64 views
1

我在我的应用程序上使用ActinCable,并且我遇到了授权问题。目前,actioncable试图授权在网站上生活的每一个人,一如既往。仅将用户连接到ActionCable

这将在我的日志中返回一个恒定的流An unauthorized connection attempt was rejected。现在这是因为访问那些人没有登录,也试图获得访问权限。

connection.rb看起来是这样的:

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

    def connect 
     self.current_user = find_verified_user 
    end 

    protected 

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

现在我想知道如果我可以让这个只有那些签署人,努力成为受connnection.rb而是采用了现场每一位来访者的授权。我对ActionCable非常不熟悉,不知道如何限制这一点 - ActionCable的文档还处于早期阶段。

回答

2

当调用ActionCable.createConsumer()时,连接尝试是。您应该尝试仅在用户登录时调用它。

相关问题