Kotoba.Collab.Channel (Kotoba v0.5.0)

Copy Markdown View Source

A Phoenix Channel with authenticated, read-only-aware collaboration.

defmodule MyAppWeb.CollabChannel do
  use Kotoba.Collab.Channel, supervisor: MyApp.CollabSupervisor

  def authorize(socket, document_id, action) do
    if MyApp.can_access?(socket.assigns.current_user, document_id, action),
      do: :ok, else: {:error, :forbidden}
  end
end

authorize/3 is required and runs on join and every transaction, awareness message and flush. action is :read or :write. Role claims also bound permissions: a read token cannot write. Configure the socket transport's max_frame_size as well as this module's message limit.