Access env['warden'].user from ApplicationCable is nil

432 Views Asked by At

So I am trying to implement dervise-jwt in a Rails 5.2 application. My login is working properly, and the tokens are being created. That being said, I want to access that same current_user from my ActionCable. Following some online tutorials, my app/channels/application_cable/connection.rb looks like this:

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

When I debug the code, env['warden'].user is nil. What do I have to do to get the current_user accessible via warden?

0

There are 0 best solutions below