Skip to content

Commit

Permalink
fix: Fix old API compatibility (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecabaco authored Oct 19, 2023
1 parent 6e1cb09 commit 0c6328c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/extensions/postgres_cdc_rls/subscriptions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ defmodule Extensions.PostgresCdcRls.Subscriptions do
%{"table" => table} ->
{:ok, ["public", table, []]}

map when is_map_key(map, "user_token") or is_map_key(map, "auth_token") ->
{:error,
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to: <redacted>"}

error ->
{:error,
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to: #{inspect(error)}"}
Expand Down
13 changes: 7 additions & 6 deletions lib/realtime_web/channels/realtime_channel.ex
Original file line number Diff line number Diff line change
Expand Up @@ -581,12 +581,13 @@ defmodule RealtimeWeb.RealtimeChannel do
end
end

defp pg_change_params(false, params, channel_pid, claims, sub_topic) do
case String.split(sub_topic, ":", parts: 3) do
[schema, table, filter] -> %{"schema" => schema, "table" => table, "filter" => filter}
[schema, table] -> %{"schema" => schema, "table" => table}
[schema] -> %{"schema" => schema}
end
defp pg_change_params(false, _, channel_pid, claims, sub_topic) do
params =
case String.split(sub_topic, ":", parts: 3) do
[schema, table, filter] -> %{"schema" => schema, "table" => table, "filter" => filter}
[schema, table] -> %{"schema" => schema, "table" => table}
[schema] -> %{"schema" => schema}
end

[
%{
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule Realtime.MixProject do
def project do
[
app: :realtime,
version: "2.25.3",
version: "2.25.4",
elixir: "~> 1.14.0",
elixirc_paths: elixirc_paths(Mix.env()),
start_permanent: Mix.env() == :prod,
Expand Down
34 changes: 33 additions & 1 deletion test/realtime/extensions/cdc_rls/subscriptions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,39 @@ defmodule Realtime.Extensions.CdcRlsSubscriptionsTest do
]

assert {:error,
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to."} =
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to: %{}"} =
S.create(conn, "supabase_realtime_test", params_list, self(), self())

params_list = [
%{
claims: %{
"role" => "anon"
},
id: UUID.uuid1(),
params: %{
"user_token" => "potato"
}
}
]

assert {:error,
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to: <redacted>"} =
S.create(conn, "supabase_realtime_test", params_list, self(), self())

params_list = [
%{
claims: %{
"role" => "anon"
},
id: UUID.uuid1(),
params: %{
"auth_token" => "potato"
}
}
]

assert {:error,
"No subscription params provided. Please provide at least a `schema` or `table` to subscribe to: <redacted>"} =
S.create(conn, "supabase_realtime_test", params_list, self(), self())

%Postgrex.Result{rows: [[num]]} =
Expand Down

0 comments on commit 0c6328c

Please sign in to comment.