Actioncable settings when not using Devise for authentication

123 views Asked by At

Normally if you're using devise, you can do current_user = env['warden'].user in the connection.rb file , but when you create your own authentication from scratch...what would it be?

channels/application_cable/connection.rb

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

    def connect
      self.current_user = find_verified_user
      logger.add_tags "ActionCable", "User #{current_user.id}"
    end

    protected

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

There are 0 answers