Colton Hagan

Joined

50 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in How can I have two connections in ActionCable?

I have Notifications Channel and a Pings Channel. Notifications are identified by my devise modal Agents. But my Pings Channel needs to be identified by my other devise modal, Users. Heres some sudocode to explain better. This would be ideal:

connection.rb
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_agent
        identified_by :current_user

    def connect
      self.current_agent = find_verfied_agent
            self.current_user = find_verfied_user
    end

    protected

    def find_verfied_agent
      if current_agent = env['warden'].user
        current_agent
      else
        reject_unauthorized_connection
      end
    end

        def find_verfied_user
      if current_user = env['warden'].user
        current_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

After searching I found this on stack overflow:
https://stackoverflow.com/questions/41672673/multiple-connections-in-actioncable

So basically the same question.

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.