kirillplatonov / hotwire-livereload

Live reload gem for Hotwire Rails apps.
MIT License
483 stars 28 forks source link

Auhorization for verified users #19

Open lentrup opened 2 years ago

lentrup commented 2 years ago

I noticed that the gem only works when I am logged in. I am using devise. Maybe we can add a hint that one needs to modify connection.rb or add something to the initializer of the gem? connection.rb :

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 = env['warden'].user
        p verified_user
        verified_user
      else
        p verified_user
        reject_unauthorized_connection
      end
    end
  end
end