jeroen11dijk

jeroen11dijk

Custom reset password form has no validation when submitting

I made my own authentication forms using ash_authentication as basis so I have more flexibility especially when it comes to styling. It works for almost everything only the validations does not work for :request_password_reset_with_password. I set up my form like:

    form =
      AshPhoenix.Form.for_action(User, :request_password_reset_with_password,
        api: Account,
        as: "user",
        context: %{private: %{ash_authentication?: true}}
      )
      |> to_form()

And it does enter my validate form:

  def handle_event("validate", %{"user" => params}, socket) do
    %{form: form} = socket.assigns
    form = AshPhoenix.Form.validate(form, params)
    {:noreply, assign(socket, form: form)}
  end

where user has a validation on email:

  validations do
    validate match(:email, ~r/(^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$)/) do
      message "must be a valid email address"
    end
  end

And which also works for the registration form so Im not sure what Im doing wrong. Only resource I found was a discord archived support page where it was said to use:
context: %{private: %{ash_authentication?: true}}. But all of the examples of what Im trying to do can just use the validate and it seems to work, although using a bit of a different setup so if more information is needed let me know.

Most Liked

zachdaniel

zachdaniel

Creator of Ash

Ah, okay, right. So, unfortunately, validations don’t work on read actions. I’ve been meaning to add a compatibility layer for this to allow validations to support queries in addition to change sets (essentially operating only on arguments). In the meantime, what you will need to do to work around this is add a preparation.

preparations do
  prepare ValidateEmail, where: [action_is(:request_password_reset_with_password)]
end

That ValidateEmail would be a standard hand-written preparation.

This is a pretty clear thing we can improve in the framework, and I hope to address this soon to make it a better experience.

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
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
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
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
srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call t...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29377 241
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
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
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement