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
Last Post!
exmanga
hm, adding something like this in the controller doesn’t help
plug :scrub_params, "user" when action in [:create]
0
Popular in Questions
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
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? Ecto.Repo — Ecto v3.14.0 has exampl...
New
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
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
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
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
New
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
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










