Validate if current user is valid

i in the following code

 @impl true
  def handle_event("validate", %{"user" => user_params}, socket) do
      email = user_params["email"]
      password = user_params["password"]

      case confirm_user(user_params) do

        {:ok, user} ->
          IO.inspect("el usuario esta habilitado a entrar")

          changeset =
            socket.assigns.user
            |>Accounts.change_user(user_params)
          {:noreply, assign_form(socket, changeset)}

        {:error, user} ->
          IO.inspect("usuario no habilitado")

          changeset =
            socket.assigns.user
            |>Accounts.change_user(user_params)
            |> Map.put(:action, :validate)

            {:noreply, assign_form(socket, changeset)}
        end
 end

I am managing to validate if the user is valid or not
but i need to display a message in my frontend saying the user is invalid in the form

currently managed to display a message that says can’t be blank but i need put a message that says invalid email or password

image

i need changed the currently message for it say: email or password invalid

I hope I understood the question, but I think you’re wanting to change the default “can’t be blank” message? If so, you can add the :message option to your validate_required call (presumably in User.changeset, or validate_email/validate_password if using mix phx.gen.auth):

validate_required(changeset, [:email, :password], message: "email or password invalid")

(This works for all validations/constraints, not just validate_required)

1 Like