Skip to content

Commit

Permalink
Setup base channel authentication for action cable
Browse files Browse the repository at this point in the history
  • Loading branch information
joekrump committed Jul 13, 2023
1 parent 1ede418 commit 1270bf9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/channels/application_cable/connection.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
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 verified_user = User.find_by(id: cookies.signed['user.id'])
verified_user
else
reject_unauthorized_connection
end
end
end
end

0 comments on commit 1270bf9

Please sign in to comment.