slouchpie
Fellow Elixir devs,
I am about to eat a sandwich and a cup of tea so sorry if this question is badly phrased.
Basically, I am working on app that uses LiveView for every page except for auth pages, which were generated using phx_gen_auth.
Recently, I wanted to use LiveView Hooks to get browser-detected “timezone” as default value in a select field on the registration form, so I started turning it into a LiveView. It actually works fine except that I want to log the user in after they register and the user_auth.ex function to log_in_user requires a Plug.Conn. I know I cannot access the conn from a LiveView so I wonder should I just stop this.
My questions are:
- has anyone had any success doing this?
- is it a bad idea to use LiveView for this part of the app?
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello!
Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app.
I creat...
New
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted”
Version...
New
Other Trending Topics
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #blog-post
- #ai
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 5- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
slouchpie
For posterity: I have decided to do this by putting my form in a live view like this:
and then I just use https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.Helpers.html#live_render/3 in
user_registration.html.eex.this way the liveview doesn’t need access to the conn but i can still get hooks in my registration form.
Note that if you’re doing this you need to pass the changeset using the
sessionoption oflive_render/3.LostKobrakai
You’ll need classical controllers for everything needing to modify the session. So as you did you can handle the forms in liveview, but they need to submit to a controller. This also kinda means you might need to share some form handling / changeset stuff between the liveview and the controller.
Same goes for logout, which needs to be in a controller given it needs to remove stuff from the session. This however is usually not a problem given it’s often just handled as a
link/2withmethod: :deleteand not a manually created form.f0rest8
This isn’t specifically about the time zone portion, but I wrote a 2 part guide to modifying your app to turn registration page into a Live View page with phx_gen_auth.
You may only be interested in part 1, the second deals with a multi-part form.
Part 1
Part 2
Hope it helps
slouchpie
I am going even further than this now. I want to turn the “settings” page into a LiveView. Have you done this before? The main problem is that we have to pass a
connstruct toUserAuth.log_in_user.f0rest8
Great to hear! I actually have done that, but I haven’t written a guide on it yet. One way to approach it, as I decided to do, can be figured out by following the archived example from Dashbit’s bytepack_archive.
It’s a bit more complicated than the registration flow since it uses
live_component, especially adding the two-factor authentication with their nimble totp library, but it works amazingly.Then, it’s just expanding on your application a bit to possibly break a single settings page into a Live View page with interactive tabs (tabbed pages) — but that’s just dependent on your app’s preferences.
Oh, lastly, it’s worth noting that it is a similar concept as before (and as @LostKobrakai mentioned), where you interact with your
phx_gen_authgenerated controllers through your Live View process. Typically, you can just make the swap betweenconnandsocketthanks to how Phoenix is designed.In a
.leextemplate file allconnreferences aresocketreferences and vice versa for a.eextemplate. The Programming Phoenix 1.4 book helps explain how Phoenix handles the connection (and many other things).I would start by cloning the Bytepack archive, then looking over how they implement their settings page. It’s an incredibly great learning resource.
In the meantime, I’ll post back here if/when I write a Medium guide on it. Good luck!