connection.rb 439 B

1234567891011121314151617181920
  1. module ApplicationCable
  2. class Connection < ActionCable::Connection::Base
  3. identified_by :current_user
  4. def connect
  5. self.current_user = find_verified_user
  6. logger.add_tags "ActionCable", "User #{current_user.id}"
  7. end
  8. protected
  9. def find_verified_user
  10. if current_user = env['warden'].user
  11. current_user
  12. else
  13. reject_unauthorized_connection
  14. end
  15. end
  16. end
  17. end