Преглед на файлове

Configure ActionCable to authenticate with Devise and use Redis by default

Chris Oliver преди 6 години
родител
ревизия
aea6b4e0ee
променени са 2 файла, в които са добавени 33 реда и са изтрити 0 реда
  1. 20 0
      app/channels/application_cable/connection.rb
  2. 13 0
      config/cable.yml

+ 20 - 0
app/channels/application_cable/connection.rb

@@ -0,0 +1,20 @@
+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

+ 13 - 0
config/cable.yml

@@ -0,0 +1,13 @@
+development:
+  adapter: redis
+  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+  channel_prefix: streaming_logs_dev
+
+test:
+  adapter: async
+
+production:
+  adapter: redis
+  url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
+  channel_prefix: streaming_logs_production
+