Sounds frustrating to say the least… here’s an attempt to recap this redirect loop based on the logs.
-
GET /=>live "/", OrganizationLive.Show, :index, as: :home
wheretrue <- Organizations.member?(socket.assigns.current_organization, user)
inon_mount(:redirect_if_user_is_member, ...)
matches so user is redirected to/app/events -
/app/events=>live "/", IndexList, :upcoming
whereif socket.assigns.current_user do
inon_mount(:ensure_authenticated, ...)
is falsey so user is redirected tolive "/users/log_in" -
live /users/log_in=>UserLive.Login
whereif conn.assigns[:current_user] do
inredirect_if_user_is_authenticated/2
is truthy so user is redirected tosigned_in_path(conn)
and this then goes back to the step 1 withGET /
sincemix phx.gen.authaddsdefp signed_in_path(_conn), do: ~p"/"in theUserAuthmodule
So the user stuck in a loop somehow meets the following conditions:
# Step 1
Organizations.member?(socket.assigns.current_organization, user)` => truthy
# Step 2
socket.assigns.current_user => falsey
# Step 3
conn.assigns[:current_user] => truthy
It seems like Step 2 should be truthy as well, but is not for some mysterious reason.
What does your mount_current_user/2 and Organizations.member/2 functions look like? As a sanity check, I’d investigate whether the former is somehow returning nil which could be a problem if the latter somehow returns true when passed a nil as a user.


















