diff --git a/README.md b/README.md index 14b6c6a9..615ea428 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ In multi-tenancy apps it's often important to authorize your subscriptions: config.turbo.base_stream_channel_class = "ApplicationCable::Channel" ``` -You can now implement your domain authorization: +You can now implement your domain authorization which will be used by `Turbo::StreamsChannel` and any other Channel inheriting from `ApplicationCable::Channel`: ```rb # app/channels/application_cable/channel.rb diff --git a/app/channels/turbo/streams_channel.rb b/app/channels/turbo/streams_channel.rb index c661eed9..2211ed59 100644 --- a/app/channels/turbo/streams_channel.rb +++ b/app/channels/turbo/streams_channel.rb @@ -6,16 +6,13 @@ # If the signed stream name cannot be verified, the subscription is rejected. # # It's important to understand that while stream names are signed, Turbo::StreamsChannel doesn't authenticate connections or -# authorize subscriptions. You can configure Turbo::StreamChannel to use e.g your ApplicationCable::Channel to -# implement authorization: +# authorize subscriptions. You can configure Turbo::StreamsChannel to use e.g your ApplicationCable::Channel to +# implement authorization in your config/application.rb: # -# # config/initializers/turbo.rb -# Rails.application.config.to_prepare do -# Turbo.base_stream_channel_class = "ApplicationCable::Channel" -# end +# config.turbo.base_stream_channel_class = "ApplicationCable::Channel" # # You can also choose which channel to use via: -# <%= turbo_stream_from "room", channel: CustomChannel %> +# <%= turbo_stream_from "room", channel: CustomChannel %> # # Note that any channel that listens to a Turbo::Broadcastable compatible stream name # (e.g verified_stream_name_from_params) can also be subscribed to via Turbo::StreamsChannel. Meaning that you should diff --git a/lib/turbo-rails.rb b/lib/turbo-rails.rb index 07b52fd8..50beca2e 100644 --- a/lib/turbo-rails.rb +++ b/lib/turbo-rails.rb @@ -1,5 +1,4 @@ require "turbo/engine" -require "turbo/railtie" require "active_support/core_ext/module/attribute_accessors_per_thread" module Turbo diff --git a/lib/turbo/engine.rb b/lib/turbo/engine.rb index ecfd82e0..19250fe0 100644 --- a/lib/turbo/engine.rb +++ b/lib/turbo/engine.rb @@ -78,6 +78,12 @@ class Engine < Rails::Engine end end + initializer "turbo.configure" do |app| + if base_class = app.config.turbo&.base_stream_channel_class + Turbo.base_stream_channel_class = base_class + end + end + initializer "turbo.helpers", before: :load_config_initializers do ActiveSupport.on_load(:action_controller_base) do include Turbo::Streams::TurboStreamsTagBuilder, Turbo::Frames::FrameRequest, Turbo::Native::Navigation diff --git a/lib/turbo/railtie.rb b/lib/turbo/railtie.rb deleted file mode 100644 index 1cebe3cb..00000000 --- a/lib/turbo/railtie.rb +++ /dev/null @@ -1,11 +0,0 @@ -module Turbo - class Railtie < ::Rails::Railtie - config.turbo = ActiveSupport::OrderedOptions.new - - initializer "turbo.configure" do |app| - if base_class = app.config.turbo&.base_stream_channel_class - Turbo.base_stream_channel_class = base_class - end - end - end -end