flmel

flmel

Hello Everyone,
I’m trying to make Pow register form validation trough LiveView which I more or less succeeded at. However, upon user creation pow normally would log the user trough the plug:
from pow docs

 def create(conn, %{"user" => user_params}) do
    conn
    |> Pow.Plug.create_user(user_params)
    |> case do
      {:ok, user, conn} ->
        conn
        |> put_flash(:info, "Welcome!")
        |> redirect(to: Routes.page_path(conn, :index))
       ...
   end

My LiveView event currently looks like this (i had to create a custom function create_user in order to escape the conn needed for the Plug but now Im trying to figure out how to log in the user on creation…

def handle_event("save", %{"user" => user_params}, socket) do
    case Accounts.create_user(user_params) do
      {:ok, _user} ->
        # Form is valid
        {:stop,
         socket
         |> put_flash(:info, "user created")  
         |> redirect(to: Routes.live_path(socket, MyApp.SearchLive))}
..

So basically is there a way to pass the conn trough my liveview or i shall copy/write the entire functionality myself.

@danschultzer somewhere in the forum you’ve mentioned that you would put a demo with liveview did you ever get around to do that ?

Thanks for your time

Showing Posts 1 to 10

andreaseriksson

andreaseriksson

Why do you want this in a LiveView?

flmel

flmel OP

Very good question, this was a task given to me by a “mentor”. Initially I got that as to validate the form on the fly and I believe most of the app would move into liveview and the form would expand.

PS. looking into your profile its the first time i get to know about fullstackphoenix. Thank you for your time keeping this up

andreaseriksson

andreaseriksson

Thanks.

I can’t say for sure its a bad idea to have a live validation on the registration (or login) form but it seems overly complicated and could be a security risk. Especially if you check for if email is already used. I just can’t see the upside other than learning how it works behind the scenes.

Schultzer

Schultzer

I don’t want to ruin your learning experience but take a look at the pow/lib/pow/phoenix/controllers/registration_controller.ex at main · pow-auth/pow · GitHub

I would also go through this issue Instructions for WebSocket usage (e.g. Phoenix Channels and LiveView) · Issue #271 · pow-auth/pow · GitHub

The last thing you want to figure out is the differences between session and token based authentications and how to handle session based authentication in a LiveView socket.

danschultzer

danschultzer

Pow Core Team

You can’t set cookies in a WebSocket. You have to pass the session id value to the client and set up some custom JS client side that will set it as a cookie. There’s some security issues too. I would recommend that you only deal with auth in HTTP.

Haven’t gotten to it yet. I’m trying out a Pow implementation with Phoenix.Socket though, hopefully can take what I learn from that and add it to the Pow docs/code :slight_smile:

flmel

flmel OP

Thank you everyone!

chrismccord

chrismccord

Creator of Phoenix

This is one of the usecases I have highlighted all along for where LV shines. Imagine a registration form where you necessarily want to improve UX because it directly increases conversions. You want to give the user feedback as soon as possible when they are trying to sign up, so realtime validations are essential, but LV allows you to add it without bringing int a client side solution and all the baggage that comes with it. The outstanding issues with a full LiveView signin or registration form is the cookie session writing on login or sign up. This can’t happen over websockts so folks have two options.

  • Use phx-change on the form, but allow the regular form post to hit a controller that performs put_session
  • Use LV for phx-change and phx-submit, and perform a redirect to a session controller, with a signed token which is used to call put_session to write the session

So LV is can be used here without any of the mentioned security issues. You are of course free to use regular controllers if that’s a better fit :slight_smile:

13
Post #7
flmel

flmel OP

What I was thinking was just use the validation and post it to the pow custom controller. Thank you Chris. And exactly one of the reasons to use LV on such a simple task is the added “user value”.

Now that LV approaches v1 thanks to all the work you put in. I think it will be great to put some beginner friendly documentation. I hope I will get to the level being able to contribute back.

ondrej-tucek

ondrej-tucek

You want to give the user feedback as soon as possible when they are trying to sign up, so realtime validations are essential

You mean something like that? :slight_smile:

andreaseriksson

andreaseriksson

Sure, I know how LV validations works. I was just imagine a more simple use case where you add email and password, since Pow was mentioned. And for that use case, I think LV is overkill.

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
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
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews