why
Where is Users.c() function defined in phx.gen.auth?
Hi,
I’m looking at the code phx.gen.auth injected in my project, trying to follow the logic to better understand how phx.gen.auth works.
While looking at the code, I bumped into a function Users.c/1 for which I cannot find a definition in the referenced Users module.
This is in the module MyProject.UserRegistrationController, in the create/2 function, in the case statement:
def create(conn, %{"user" => user_params}) do
case Users.c(user_params) do
{:ok, user} ->
{:ok, _} =
Users.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
)
conn
|> put_flash(:info, "User created successfully.")
|> UserAuth.log_in_user(user)
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
Might anybody know where I can find the definition of Users.c/1 ?
Thank you.
Most Liked
kokolegorille
The code comes from priv/templates/phx.auth.gen/registration_controller.ex.
It should not look like what You have, the code is like this.
def create(conn, %{"<%= schema.singular %>" => <%= schema.singular %>_params}) do
case <%= inspect context.alias %>.register_<%= schema.singular %>(<%= schema.singular %>_params) do
{:ok, <%= schema.singular %>} ->
{:ok, _} =
<%= inspect context.alias %>.deliver_<%= schema.singular %>_confirmation_instructions(
<%= schema.singular %>,
&Routes.<%= schema.route_helper %>_confirmation_url(conn, :confirm, &1)
)
conn
|> put_flash(:info, "<%= schema.human_singular %> created successfully.")
|> <%= inspect schema.alias %>Auth.log_in_<%= schema.singular %>(<%= schema.singular %>)
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
But I also see You have Users… You probably did not use the right parameters. It should be
mix phx.gen.auth Accounts User users
context plural (or not), schema singular, table plural.
APB9785
That function Users.c/1 should be Users.register_user/1 in lib/app_name/users.ex. Is it possible that at some point you made an accidental change to the file?
why
Thank you both for the help ![]()
I just created a new Phoenix test project and ran the phx.gen.auth generator there.
This time I used mix phx.gen.auth UserAccounts User users (I cannot use Accounts, as I need that for something else).
Now the result looks good, with a call to UserAccounts.register_user/1:
def create(conn, %{"user" => user_params}) do
case UserAccounts.register_user(user_params) do
{:ok, user} ->
{:ok, _} =
UserAccounts.deliver_user_confirmation_instructions(
user,
&Routes.user_confirmation_url(conn, :confirm, &1)
)
conn
|> put_flash(:info, "User created successfully.")
|> UserAuth.log_in_user(user)
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, "new.html", changeset: changeset)
end
end
Popular in Discussions
Other popular topics
Latest Phoenix Threads
Chat & Discussions>Discussions
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
- #forms
- #api
- #metaprogramming
- #hex
- #security










