diff --git a/app/channels/turbo/streams_channel.rb b/app/channels/turbo/streams_channel.rb index 65a6abf2..0390938f 100644 --- a/app/channels/turbo/streams_channel.rb +++ b/app/channels/turbo/streams_channel.rb @@ -5,32 +5,21 @@ # using the view helper Turbo::StreamsHelper#turbo_stream_from(*streamables). # If the signed stream name cannot be verified, the subscription is rejected. # -# In case if custom behavior is desired, one can create their own channel and re-use some of the primitives from -# helper modules like Turbo::Streams::StreamName: +# 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: # -# class CustomChannel < ActionCable::Channel::Base -# extend Turbo::Streams::Broadcasts, Turbo::Streams::StreamName -# include Turbo::Streams::StreamName::ClassMethods -# -# def subscribed -# if (stream_name = verified_stream_name_from_params).present? && -# subscription_allowed? -# stream_from stream_name -# else -# reject -# end -# end -# -# def subscription_allowed? -# # ... -# end +# # config/initializers/turbo.rb +# Rails.application.config.to_prepare do +# Turbo.base_stream_channel_class = "ApplicationCable::Channel" # end # -# This channel can be connected to a web page using :channel option in -# turbo_stream_from helper: -# -# <%= turbo_stream_from 'room', channel: CustomChannel %> +# You can also choose which channel to use via: +# <%= 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 +# never use the turbo_stream_from :channel option to implement authorization. class Turbo::StreamsChannel < Turbo.base_stream_channel_class.constantize extend Turbo::Streams::Broadcasts, Turbo::Streams::StreamName include Turbo::Streams::StreamName::ClassMethods