From 01cc5aa3a145b24f07c3ab38acbbb3a406556fd8 Mon Sep 17 00:00:00 2001 From: Moritz Date: Fri, 9 Jan 2026 05:25:59 +0100 Subject: [PATCH] Add current_actor/1 helper for consistent actor access Provides a single function to access current_user from socket assigns across all LiveViews, ensuring consistent access pattern. --- lib/mv_web/live_helpers.ex | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/mv_web/live_helpers.ex b/lib/mv_web/live_helpers.ex index f217ee2..6af71ec 100644 --- a/lib/mv_web/live_helpers.ex +++ b/lib/mv_web/live_helpers.ex @@ -59,4 +59,19 @@ defmodule MvWeb.LiveHelpers do user end end + + @doc """ + Helper function to get the current actor (user) from socket assigns. + + Provides consistent access pattern across all LiveViews. + Returns nil if no current_user is present. + + ## Examples + + actor = current_actor(socket) + members = Membership.list_members!(actor: actor) + """ + def current_actor(socket) do + socket.assigns[:current_user] || socket.assigns.current_user + end end