22 lines
514 B
Ruby
22 lines
514 B
Ruby
module ApplicationCable
|
|
class Connection < ActionCable::Connection::Base
|
|
identified_by :current_user
|
|
|
|
def connect
|
|
super
|
|
ApplicationRecord.with_tenant(current_tenant) { set_current_user || reject_unauthorized_connection }
|
|
end
|
|
|
|
private
|
|
def set_current_user
|
|
if session = find_session_by_cookie
|
|
self.current_user = session.user
|
|
end
|
|
end
|
|
|
|
def find_session_by_cookie
|
|
Session.find_signed(cookies.signed[:session_token])
|
|
end
|
|
end
|
|
end
|