feat(chat): add auth logic for room memberships

This commit is contained in:
2024-11-17 21:16:52 +00:00
parent d3253bd900
commit 9755dc2b9e
3 changed files with 80 additions and 12 deletions

View File

@@ -33,12 +33,19 @@ defmodule SlaxWeb.ChatRoomLive.Edit do
@impl Phoenix.LiveView
def mount(%{"id" => id}, _session, socket) do
room = Chat.get_room!(id)
changeset = Chat.change_room(room)
socket =
socket
|> assign(page_title: "Edit chat room", room: room)
|> assign_form(changeset)
if Chat.joined?(room, socket.assigns.current_user) do
changeset = Chat.change_room(room)
socket
|> assign(page_title: "Edit chat room", room: room)
|> assign_form(changeset)
else
socket
|> put_flash(:error, "Permission denied")
|> push_navigate(to: ~p"/")
end
{:ok, socket}
end