From e674f71d8c73a9e96ec16f888977aa7991946b21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicklas=20Ramh=C3=B6j=20Holtryd?= Date: Tue, 22 Oct 2024 11:32:32 +0200 Subject: [PATCH] =?UTF-8?q?fixup!=20Allow=20the=20application=20to=20confi?= =?UTF-8?q?gure=20Turbo::StreamChannel=E2=80=99s=20inheritance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/channels/turbo/streams_channel.rb | 33 +++++++++------------------ 1 file changed, 11 insertions(+), 22 deletions(-) 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