Version info:
Windows 10
Erlang/OTP 21 [erts-10.0.1] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Elixir 1.7.3 (compiled with Erlang/OTP 19)
Phoenix v1.3.4
I'm following the getting started guide. Although the code examples look different now (likely due to using newer versions of Elixir and Phoenix), I think I have managed to set it up correctly.
When visiting http://localhost:4000/registration/new, I get the following error:
[error] #PID<0.394.0> running MyAppWeb.Endpoint (cowboy_protocol) terminated
Server: localhost:4000 (http)
Request: GET /registration/new
** (exit) an exception was raised:
** (Pow.Config.ConfigError) No :user configuration option found for user schema module.
(pow) lib/pow/config.ex:55: Pow.Config.raise_error/1
(pow) lib/pow/operations.ex:18: Pow.Operations.changeset/2
(pow) lib/pow/phoenix/controllers/registration_controller.ex:15: Pow.Phoenix.RegistrationController.process_new/2
(pow) lib/pow/phoenix/controllers/controller.ex:87: Pow.Phoenix.Controller.action/3
(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
(my_app) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
(my_app) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.plug_builder_call/2
(my_app) lib/plug/debugger.ex:122: MyAppWeb.Endpoint."call (overridable 3)"/2
(my_app) lib/my_app_web/endpoint.ex:1: MyAppWeb.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) c:/Code/my_app/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
Contents of config.exs:
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
# General application configuration
config :my_app, :pow,
user: MyApp.Users.User,
ecto_repos: [MyApp.Repo] # Notice that this is different from the getting started guide
# Configures the endpoint
config :my_app, MyAppWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "my_secret",
render_errors: [view: MyAppWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: MyApp.PubSub,
adapter: Phoenix.PubSub.PG2]
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:user_id]
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
Output of mix ecto.setup:
warning: could not find Ecto repos in any of the apps: [:my_app].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :my_app, ecto_repos: [...]
warning: could not find Ecto repos in any of the apps: [:my_app].
You can avoid this warning by passing the -r flag or by setting the
repositories managed by those applications in your config/config.exs:
config :my_app, ecto_repos: [...]
I'm investigating this now; trying to find the cause. If/when I figure it out, I will update this issue. Figured I'd post it here, in case other beginners encounter the same issue in the future.
In config.exs, changing this:
config :my_app, :pow,
user: MyApp.Users.User,
ecto_repos: [MyApp.Repo]
To this:
config :my_app, # Removed :pow
user: MyApp.Users.User,
ecto_repos: [MyApp.Repo]
Enabled me to run mix ecto.setup successfully.
But I suppose :pow needs to be included in config.exs, somewhere. (?)
You need to keep this part intact in your config.ex:
# General application configuration
config :my_app,
ecto_repos: [MyApp.Repo]
And append this further down:
config :my_app, :pow,
user: MyApp.Users.User,
repo: MyApp.Repo
Seems like you modified the first configuration variables instead.
I've updated the readme to make it clearer: https://github.com/danschultzer/pow#getting-started-phoenix 😄
Would you like if Pow updates these files automatically?
So you could run e.g.:
mix pow.phoenix.config
And it'll try to update config.ex, endpoint.ex and router.ex automatically, or throw errors if any of them are missing some vital parts.
I'm mostly for letting the developers configure their app themselves so they get a feeling of what's going on, but at the same time I like to make things as plug n' play as possible so the developer can get started right of the bat.
Aha, I see — my bad! Thanks for the info.
I misunderstood the guide. I think it might be clearer/easier for beginners to read the guide without the # … parts, as it would be easier to see where to place the code and what not to change. It would also clutter up the examples with unnecessary code, so maybe it's not a good idea.
Adding an auto-configration option could be useful for beginners, although I see your point of allowing more experienced developers to see how everything connects and to configure things themselves. These problems I'm encountering is mostly due to my lack of more general knowledge and experience about Elixir and how configuration works (not flaws in your library or guides).
Yeah, I'll keep the examples concise, but see how I can improve them so it's clear where to add the changes. Did you have any trouble with updating endpoint.ex or router.ex?
Yeah, good call.
No, I didn't encounter any trouble with endpoint.ex or router.ex. The only thing I was a bit uncertain about was where to place this code alongside the code which already existed within router.ex:
pipeline :protected do
plug Pow.Plug.RequireAuthenticated,
error_handler: Pow.Phoenix.PlugErrorHandler
end
scope "/" do
pipe_through :browser
pow_routes()
end
I wasn't sure whether the order in which the pipelines and scopes are placed within router.ex have any significance in terms of the application's behaviour, but I figured it doens't matter.
Hmmm. I seem to encounter the same issue when I add the config further down.
Does this look config.exs correct?:
# This file is responsible for configuring your application
# and its dependencies with the aid of the Mix.Config module.
#
# This configuration file is loaded before any dependency and
# is restricted to this project.
use Mix.Config
# General application configuration
config :my_app,
ecto_repos: [MyApp.Repo]
config :my_app, :pow,
user: MyApp.Users.User,
repo: MyApp.Repo
# Configures the endpoint
config :my_app, MyAppWeb.Endpoint,
url: [host: "localhost"],
secret_key_base: "my_secret",
render_errors: [view: MyAppWeb.ErrorView, accepts: ~w(html json)],
pubsub: [name: MyApp.PubSub,
adapter: Phoenix.PubSub.PG2]
# Configures Elixir's Logger
config :logger, :console,
format: "$time $metadata[$level] $message\n",
metadata: [:user_id]
# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
import_config "#{Mix.env}.exs"
Ah! Found the issue. I had made a really dumb typo in endpoint.ex.
Got it working now!
Great! I've updated to readme so there's a bit more explanation for the routes.ex. Thanks for all the feedback, it's super helpful for tweaking documentation!
Of course, any time. I haven't submitted a pull request before, else I'd fix it myself. I'd be happy to help out once I've learned the ropes and gotten up to speed with things 🙂
Most helpful comment
You need to keep this part intact in your
config.ex:And append this further down:
Seems like you modified the first configuration variables instead.