The actual error I am getting is:
[error] #PID<0.427.0> running UserPwaWeb.Endpoint (connection #PID<0.426.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: GET /registration/new
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Phoenix.HTML.FormData not implemented for #Ecto.Changeset<action: nil, changes: %{}, errors: [password_hash: {"can't be blank", [validation: :required]}, password: {"can't be blank", [validation: :required]}, email: {"can't be blank", [validation: :required]}], data: #Db.Users.User<>, valid?: false>. This protocol is implemented for: Plug.Conn
...
The problem could just be my lack of understanding with umbrella projects.
To reproduce the error I first created a new umbrella project. I created apps called UserPwa & Db within the apps folder and added pow
to the mix.exs
for both of them. I add {:db, in_umbrella: true}
to the UserPwa mix.exs
file. After running mix deps.get
I cd
into my Db app and run mix pow.ecto.install
.
After that I cd
into my interface app UserPwa and add:
config :user_pwa, :pow,
user: Db.Users.User
repo: Db.Repo
to my config/config.ex
. I then add plug Pow.Plug.Session, otp_app: :user_pwa
to my user_pwa_web/endpoint.ex
file, making sure to include it directly after the Plug.Session
plug.
After that I added to my router:
use Pow.Phoenix.Router
..
pipeline :protected do
plug Pow.Plug.RequireAuthenticated,
error_handler: Pow.Phoenix.PlugErrorHandler
end
scope "/" do # Note the lack of UserPwaWeb (I'm assuming this is on purpose because of how the action is sent to the RegistrationController?)
pipe_through :browser
pow_routes()
end
The only thing that I had to do extra that wasn’t in the docs (that I immediately saw) was that I had to add the mix ecto.setup
alias to my mix file.
I added a new aliases function to my Db app’s config:
defp aliases do
[
"ecto.setup": ["ecto.create", "ecto.migrate", "run priv/repo/seeds.exs"],
"ecto.reset": ["ecto.drop", "ecto.setup"],
test: ["ecto.create --quiet", "ecto.migrate", "test"]
]
end
After that I run mix ecto.setup
it warns me that the seeds script failed because there really isn’t a seeds file created yet, and then I start up the server.
The full error is:
[error] #PID<0.438.0> running UserPwaWeb.Endpoint (connection #PID<0.429.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: GET /registration/new
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Phoenix.HTML.FormData not implemented for #Ecto.Changeset<action: nil, changes: %{}, errors: [password_hash: {"can't be blank", [validation: :required]}, password: {"can't be blank", [validation: :required]}, email: {"can't be blank", [validation: :required]}], data: #Db.Users.User<>, valid?: false>. This protocol is implemented for: Plug.Conn
(phoenix_html) deps/phoenix_html/lib/phoenix_html/form_data.ex:1: Phoenix.HTML.FormData.impl_for!/1
(phoenix_html) deps/phoenix_html/lib/phoenix_html/form_data.ex:15: Phoenix.HTML.FormData.to_form/2
(phoenix_html) lib/phoenix_html/form.ex:287: Phoenix.HTML.Form.form_for/4
(pow) lib/pow/phoenix/templates/registration_template.ex:3: Pow.Phoenix.RegistrationTemplate.render/2
(user_pwa) lib/user_pwa_web/templates/layout/app.html.eex:26: UserPwaWeb.LayoutView."app.html"/1
(phoenix) lib/phoenix/view.ex:399: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/controller.ex:729: Phoenix.Controller.__put_render__/5
(phoenix) lib/phoenix/controller.ex:746: Phoenix.Controller.instrument_render_and_send/4
(pow) lib/pow/phoenix/controllers/registration_controller.ex:1: Pow.Phoenix.RegistrationController.action/2
(pow) lib/pow/phoenix/controllers/registration_controller.ex:1: Pow.Phoenix.RegistrationController.phoenix_controller_pipeline/2
(user_pwa) lib/user_pwa_web/endpoint.ex:1: UserPwaWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:275: Phoenix.Router.__call__/1
(user_pwa) lib/user_pwa_web/endpoint.ex:1: UserPwaWeb.Endpoint.plug_builder_call/2
(user_pwa) lib/plug/debugger.ex:122: UserPwaWeb.Endpoint."call (overridable 3)"/2
(user_pwa) lib/user_pwa_web/endpoint.ex:1: UserPwaWeb.Endpoint.call/2
(phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:34: Phoenix.Endpoint.Cowboy2Handler.init/2
(cowboy) /Users/joemarion/CharlottesWebAgency/jixler/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
(cowboy) /Users/joemarion/CharlottesWebAgency/jixler/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
(cowboy) /Users/joemarion/CharlottesWebAgency/jixler/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3