fix: add ensure_user_role_loaded to router live_session globally
This commit is contained in:
parent
675ab14fce
commit
ad0a3cd458
2 changed files with 12 additions and 3 deletions
|
|
@ -49,8 +49,14 @@ defmodule MvWeb.LiveHelpers do
|
||||||
opts = [domain: Mv.Accounts, actor: user]
|
opts = [domain: Mv.Accounts, actor: user]
|
||||||
|
|
||||||
case Ash.load(user, :role, opts) do
|
case Ash.load(user, :role, opts) do
|
||||||
{:ok, loaded_user} -> loaded_user
|
{:ok, loaded_user} ->
|
||||||
{:error, _} -> user
|
loaded_user
|
||||||
|
|
||||||
|
{:error, error} ->
|
||||||
|
# Log warning if role loading fails - this can cause authorization issues
|
||||||
|
require Logger
|
||||||
|
Logger.warning("Failed to load role for user #{user.id}: #{inspect(error)}")
|
||||||
|
user
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,10 @@ defmodule MvWeb.Router do
|
||||||
AshAuthentication-specific: We define that all routes can only be accessed when the user is signed in.
|
AshAuthentication-specific: We define that all routes can only be accessed when the user is signed in.
|
||||||
"""
|
"""
|
||||||
ash_authentication_live_session :authentication_required,
|
ash_authentication_live_session :authentication_required,
|
||||||
on_mount: {MvWeb.LiveUserAuth, :live_user_required} do
|
on_mount: [
|
||||||
|
{MvWeb.LiveUserAuth, :live_user_required},
|
||||||
|
{MvWeb.LiveHelpers, :ensure_user_role_loaded}
|
||||||
|
] do
|
||||||
live "/", MemberLive.Index, :index
|
live "/", MemberLive.Index, :index
|
||||||
|
|
||||||
live "/members", MemberLive.Index, :index
|
live "/members", MemberLive.Index, :index
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue