exmanga

exmanga

Hi!

I have a problem after modifying the standard registration flow from Phauxth. I have generated the auth with Phauxth and modified it to add first_name, last_name and password confirmation and changed the route scope to /admin. The registration works fine if all fields are provided, but if there is a validation error, it fails with the following message:

ArgumentError at POST /admin/users
cannot convert nil to param

The code looks like this:

Form:

<%= form_for @changeset, user_path(@conn, :create), fn f -> %>
<%= if @changeset.action do %>
  <div class="alert alert-danger">
    <p>Please check the errors below.</p>
  </div>
<% end %>

  <div class="form-group">
    <%= text_input f, :first_name %>
    <%= error_tag f, :first_name %>
  </div>

  <div class="form-group">
    <%= text_input f, :last_name %>
    <%= error_tag f, :last_name %>
  </div>

  <div class="form-group">
    <%= email_input f, :email %>
    <%= error_tag f, :email %>
  </div>

  <div class="form-group">
    <%= password_input f, :password %>
    <%= error_tag f, :password %>
  </div>

  <div class="form-group">
    <%= password_input f, :password_confirmation %>
    <%= error_tag f, :password_confirmation %>
  </div>

    <%= submit "Register" %>
<% end %>

user_controller.ex

  def create(conn, %{"user" => %{"email" => email} = user_params}) do
    key = Phauxth.Token.sign(conn, %{"email" => email})

    case Accounts.create_user(user_params) do
      {:ok, user} ->
        Log.info(%Log{user: user.id, message: "user created"})
        Accounts.Message.confirm_request(email, key)
        success(conn, "User created successfully", session_path(conn, :new))

      {:error, %Ecto.Changeset{} = changeset} ->
        render(conn, "new.html", changeset: changeset)
    end
  end

accounts.ex

  def create_user(attrs) do
    %User{}
    |> User.create_changeset(attrs)
    |> Repo.insert()
  end

user.ex

  def create_changeset(%User{} = user, attrs) do
    user
    |> cast(attrs, [:first_name, :last_name, :email, :password])
    |> validate_required([:first_name, :last_name, :email, :password])
    |> unique_email
    |> validate_confirmation(:password)
    |> validate_password(:password)
    |> put_pass_hash
  end

router.ex

  scope "/admin", MyApp do
    resources "/users", Admin.UserController
  end

If I inspect the changeset it looks like this:

#Ecto.Changeset<
  action: :insert,
  changes: %{
    email: "email@gmail.com",
    last_name: "last name",
    password: "password"
  },
  errors: [
    password_confirmation: {"does not match confirmation",
     [validation: :confirmation]},
    first_name: {"can't be blank", [validation: :required]}
  ],
  data: #MyApp.Accounts.User<>,
  valid?: false

Appreciate any help with this.

Showing Posts 1 to 3

exmanga

exmanga OP

Anyone?

Or maybe I should just dump this and go with Ueberauth?

OvermindDL1

OvermindDL1

I’ve not used phauxth but from the message I’d guess the params need a scrub plug before it?

exmanga

exmanga OP

hm, adding something like this in the controller doesn’t help

plug :scrub_params, "user" when action in [:create]

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
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
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
RemyXRenard
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
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
samoloth
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
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

Other Trending Topics Top

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
marciok
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews