After logout and then re-login conn.assigns[:current_user] is nil

After logout and then re-login conn.assigns[:current_user] is nil. If I go with another login, it reads the user.
I use current_user.role for redirecting to proper page, but cause of empty user I get an error.
Phoenix version 1.5.7, phx_gen_auth 0.7.0

Thanks!

I don’t think anyone could help you when you just post this, you should make a minimal GitHub repo demonstrating the issue IMO.

3 Likes

in log_in_user function signed_in_path reads where to redirect user on login.
If I do a logout and login again, user is not read in conn.assigns
If I do a login again it reads the user properly

def log_in_user(conn, user, params \\ %{}) do
..
  redirect(to: user_return_to || signed_in_path(conn))
end

defp signed_in_path(conn) do
  IO.inspect(conn.assigns[:current_user], label: "current_user")
  
  if has_role?(conn.assigns[:current_user], :admin) do
      # Application.get_env(:Qr, :sign_in_path)
      "/items"
    else
      "/"
    end
  end

It looks that role library was redirecting before signed_in_path did.
Solved