1

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?

Pro777
  • 1,684
  • 1
  • 18
  • 30
  • I have very similar Connection and have found that after reloading the page several times, then user shows up. It feels like a race condition between loading the session and establishing the Connection, but I haven't been able to track down where it is. – Troy Apr 14 '21 at 22:19

0 Answers0