How to use phx gen auth in a live application?

So, I am starting a new phoenix project, and of course I’m going to implement it all using live views. So I have one question: does phx_gen_auth work well with live views? I know that the generated code does generate only dead views, and I don’t care too much about that, I will probably replace them with live views in the future.

But there is this line that got me thinking:

It looks like there is actually a right way to put phx_gen_auth and live views together, but I couldn’t find it on the docs and neither found any tutorial explaining that specifically. Do I have to do something else on my live views? Besides manually setting the user to the socket assigns, and authorization, which I already noticed I have to.


Alright, I actually think I discovered, the live_socket_id key on session is used by LiveView under the hood to identify connections, so if the value changes and the connection gets down, it will fail reconnecting cause the session is not the same anymore. So no extra work needed here, only the work I already expected with the assigns and authorization.


Hi … check this out


Oh! Thank you so much! That makes it a lot clearer :smiley:

1 Like

And thanks @redrapids for the video :smiley: I already was interested on, now that I had a little taste of it I’m keen to sign up for it.

1 Like

Many thanks! Allow me to say a few words about our editorial process. We consider three things: MY interest in a topic (passion comes through in teaching); content PERFORMANCE, and the overarching Groxio mission: teach programmers interesting concepts in a fun and engaging way on a regular basis.

We were in the air about doing another Elixir series, because the market is pretty saturated compared to the language size. But the LiveView one was popular enough that we decided to continue for one more year, adding sessions for nerves, Ecto, and property-based testing.

So for those who like it, the ways you can advocate for more are:

  • subscribe to our channel (we’re currently short about 100 subscribers to start monetizing that content)

  • tell your friends on twitter to follow us and be noisy (we’re @groxioLearning and @redrapids and our marketing is grass roots social media),

  • get a paid subscription. The way we measure the effectiveness of content is how many yearly subscribers we get while a module is active.

In short, we love Elixir and want to keep producing content, but it has to put food on the table first!

An offer for those on the board. Subscribe annually, and we’ll let you keep the Elixir content we’ve released so far:Elixir/OTP/LiveView (and our subscription model means you will also get to keep the Nerves, Ecto, and prop test modules we will build later this year. Just tweet that you’ve subscribed, and at me: @redrapids.

Thanks again for your kind words!


Thanks so much!

1 Like