alexslade
Loading relationships from session
Alternative title: A yearning for mackerel
I have a specific problem (I want to load a :team resource on the current_user that AshAuthentication puts into conn assigns. I could do this as a follow-on query, but I’m trying to do it in one).
But really, I want to learn to fish solve this myself.
I tried adding a preparation, at first to the global preparations, and later to get_by_subject which seems to be used by the password strategy.
Either way, I get errorless redirects back to the sign-in page as if I wasn’t logged in. I can’t see anything with logging set to :debug, I can’t see anything relevant with log_successful_policy_breakdowns or policy_breakdowns turned on.
What are my next steps for finding out why ash_auth is failing here? I’m assuming there must be another way to get to an error code, though I accept it may be something that I simply need to understand and avoid. (I also assume there may be a better way of doing this team load).
Any tips are much appreciated.
Marked As Solved
barnabasJ
I think this happens here:
This calls the action on the user resource internally, and if that returns an error, nil is set as the user. It seems the tenant error is detected before any policies are run, so you don’t get a log for the team.
Not sure about how you could debug this better. But here is the approach I took.
I looked at it more like a regular bug than anything Ash specific. From the little LiveView experience I had, I knew that the user would be most likely set in a live_session. So i looked at the router setup and saw the ash_authentication_live_session setup by the ash_auth igniter and went to it’s definition. There I saw that the Module was added to the list of on_mount hooks. That lead me to look at the on_mount function in the module.
I saw the call to AshAuthentication.subject_to_user and looked at that function. There I saw the Ash.Query being constructed and the read being called.
I saw that there was this special context that would allow to bypass the policies and that there is no real actor yet. This is what I put in my first answer.
Also Liked
barnabasJ
Yeah, that was my bad. I missed the tenant being set here ash_authentication_phoenix/lib/ash_authentication_phoenix/live_session.ex at main · team-alembic/ash_authentication_phoenix · GitHub








