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.
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.
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.
For posterity, the accepted answer (the youtube video) does not actually:
Instead it uses the autogenerated HTML and controllers from phx_gen_auth and shows how to integrate that with a LiveView page. It does not solve the problem of having, e.g. registration form in a live view.
I briefly mentioned my own approach to a similar problem here: Phx_gen_auth using live view ONLY
If anyone wants more details on it, let me know.
That is nice thanks. But I see in the video he’s doing an additional query to fetch the user with the token, but fetch_current_user already does that query, so i wonder how to assign the existing fetched user to the LiveView socket (it is already attached to the conn)