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.
This commit is contained in:
parent
23f00d2cba
commit
57bcef17ca
1 changed files with 15 additions and 0 deletions
|
|
@ -59,4 +59,19 @@ defmodule MvWeb.LiveHelpers do
|
||||||
user
|
user
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue