Send auth_token for authentication to ActionCable

后端 未结 10 1761
梦毁少年i
梦毁少年i 2021-02-04 02:23
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      #puts params[:auth_token]
      self         


        
10条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-04 03:01

    Pierre's answer works. However, it's a good idea to be explicit about expecting these parameters in your application.

    For instance, in one of your config files (e.g. application.rb, development.rb, etc...) you can do this:

    config.action_cable.mount_path = '/cable/:token'
    

    And then simply access it from your Connection class with:

    request.params[:token]
    

提交回复
热议问题