exmanga

exmanga

Getting "cannot convert nil to param" error from Phauxth registration

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.

Most Liked

exmanga

exmanga

Anyone?

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

Last Post!

exmanga

exmanga

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

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

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
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
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
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
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
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

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 31586 112
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49266 226
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
AngeloChecked
What learn first? Rust or Elixir Hi Elixir community! I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New

We're in Beta

About us Mission Statement