genchemmer1234
genchemmer1234

Reputation: 43

Setting Rails config.cache_classes=false causes env['warden'].user to fail

I'm running into an issue where setting config.cache_classes=false in my development.rb causes the following method find_verified_user to not get executed.

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      self.current_user = find_verified_user
      logger.add_tags 'ActionCable', current_user.id
    end

    protected

    def find_verified_user # this checks whether a user is authenticated with devise
      if verified_user = env['warden'].user
        verified_user
      else
        reject_unauthorized_connection
      end
    end
  end
end

Upvotes: 0

Views: 78

Answers (1)

akbarbin
akbarbin

Reputation: 5105

Updated: Thanks @max for the suggestion.

You can modify your condition code into this:

module ApplicationCable
  class Connection < ActionCable::Connection::Base
    identified_by :current_user

    def connect
      verified_user = env['warden'].user
      if verified_user
        self.current_user = verified_user
        logger.add_tags 'ActionCable', current_user.id
      else
        reject_unauthorized_connection
      end
    end
  end
end

Upvotes: 0

Related Questions