Help us understand the problem. What is going on with this article?

Action Cableとdeviseの併用

More than 1 year has passed since last update.
module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_session_user

    def connect
      self.current_session_user = find_session_user
    end

    protected

    def find_session_user
      session_user = env['warden'].user(scope: :operator)
      return reject_unauthorized_connection unless session_user
      session_user
    end
  end
end

認証ユーザーのscopeが1つなら env['warden'].user だけで問題ないが、
複数あるなら scopeの指定が必要.

 env['warden'].user(scope: :operator)

devise helperの current_user のようにChannelで参照できる
Controllerのhelperではないので、devise helperの current_user と競合しないため、
current_userと定義していても問題はない

identified_by :current_session_user
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away