aaronrenner / phx_gen_auth

An authentication system generator for Phoenix 1.5 applications.
774 stars 56 forks source link

Losing conn.assigns values #37

Closed lukashambsch closed 4 years ago

lukashambsch commented 4 years ago

Before I explain my issue I will mention that I'm using {:phoenix, "~> 1.5.2"} and phoenix_live_view.

I'm seeing some strange behavior while trying to integrate this into an existing app. The 'creates account and logs the user in' test is failing for the second request in the user registrations controller. The second request in the 'logs the user in' test is also failing in the user sessions controller.

I noticed that the require_authenticated_user function is checking conn.assigns[:current_user], but login_user doesn't assign it. Where does that assign happen? In the meantime I've added the assign in to login_user.

Here's what I'm seeing for the second request in the user registration test after adding that assign:

IO.inspect(conn.assigns)
conn = get(conn, "/users/settings")
IO.inspect(conn.assigns)

The first inspect has current_user in the map, but the second one doesn't. I'm having trouble tracking down where it could've been removed.

lukashambsch commented 4 years ago

Of course 15 minutes after finally creating an issue I figure it out. The fetch_current_user plug wasn't added to my router. I modified quite a bit to get things going with my current app, so I'm not sure if it was ever added by the generator.