kelvinst

kelvinst

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: https://github.com/aaronrenner/phx_gen_auth/blob/de9596102bf59a3333d78330a0ab07f8a9ec8f4d/priv/templates/phx.gen.auth/auth.ex#L22

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.

Marked As Solved

andrewb

andrewb

Also Liked

kelvinst

kelvinst

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.

redrapids

redrapids

Author of Adopting Elixir

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!

slouchpie

slouchpie

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.

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
johnnyicon
Hi all, I've just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I'm trying to use Postg...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vegabook
I'm brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New

Other popular topics Top

skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

We're in Beta

About us Mission Statement