Skip to content

Commit

Permalink
adding auth to action cable
Browse files Browse the repository at this point in the history
  • Loading branch information
opedrosouza committed Apr 26, 2024
1 parent d8e19a8 commit 242e176
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,36 @@
module ApplicationCable

class Connection < ActionCable::Connection::Base

include SetCurrentRequestDetails

identified_by :current_user, :current_account, :true_user
# impersonates :user

delegate :params, :session, to: :request

def connect
self.current_user = find_verified_user
set_request_details
self.current_account = Current.account

logger.add_tags "ActionCable", "User #{current_user.id}", "Account #{current_account.id}"
end

protected

def find_verified_user
if (current_user = env["warden"].user(:user))
current_user
else
reject_unauthorized_connection
end
end

def user_signed_in?
!!current_user
end

end

end

0 comments on commit 242e176

Please sign in to comment.