Session issues on iOS

Sounds frustrating to say the least… here’s an attempt to recap this redirect loop based on the logs.

  1. GET / => live "/", OrganizationLive.Show, :index, as: :home
    where true <- Organizations.member?(socket.assigns.current_organization, user)
    in on_mount(:redirect_if_user_is_member, ...)
    matches so user is redirected to /app/events

  2. /app/events => live "/", IndexList, :upcoming
    where if socket.assigns.current_user do
    in on_mount(:ensure_authenticated, ...)
    is falsey so user is redirected to live "/users/log_in"

  3. live /users/log_in => UserLive.Login
    where if conn.assigns[:current_user] do
    in redirect_if_user_is_authenticated/2
    is truthy so user is redirected to signed_in_path(conn)
    and this then goes back to the step 1 with GET /
    since mix phx.gen.auth adds defp signed_in_path(_conn), do: ~p"/" in the UserAuth module

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.