Rails Devise Action Cable

前端 未结 2 1398
再見小時候
再見小時候 2021-02-20 08:01

I\'m trying to get Action Cable working with Devise.

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

    identified_by :current_us         


        
2条回答
  •  梦谈多话
    2021-02-20 08:21

    Update your connection.rb with the following:

    module ApplicationCable
      class Connection < ActionCable::Connection::Base
        identified_by :current_user
    
        def connect
          self.current_user = find_verified_user
          logger.add_tags 'ActionCable', current_user.studentid
        end
    
        protected
    
        def find_verified_user # this checks whether a user is authenticated with devise
          if verified_user = env['warden'].user
            verified_user
          else
            reject_unauthorized_connection
          end
        end
      end
    end
    

    Link: http://tutorials.pluralsight.com/ruby-ruby-on-rails/implementing-a-custom-devise-sign-in-and-actioncable-rails-5?saved=1&status=in-review

提交回复
热议问题