pow-auth / pow

Robust, modular, and extendable user authentication system
https://powauth.com
MIT License
1.6k stars 154 forks source link

PowEmailConfirmation extension crashes with UndefinedFunctionError #45

Closed NAR closed 5 years ago

NAR commented 5 years ago

Hello!

I'm trying to follow the instructions in the README about the e-mail confirmation extension. I updated the config.ex, the user.ex and the router.ex, generated the templates, added the pow_mailer.ex module, added the mailer_backend key to the config.ex, added the mailer_view function, generated the templates and added the web_mailer_module key. Yet after login I get this error message:

[error] #PID<0.417.0> running UserProfileManagerWeb.Endpoint (cowboy_protocol) terminated Server: localhost:4000 (http) Request: POST /session?request_path=%2F (exit) an exception was raised: (UndefinedFunctionError) function UserProfileManagerWeb.Router.Helpers.pow_email_confirmation_confirmation_url/3 is undefined or private (user_profile_manager) UserProfileManagerWeb.Router.Helpers.pow_email_confirmation_confirmation_url(%Plug.Conn{adapter: {Plug.Adapters.Cowboy.Conn, :...}, assigns: %{action: "/session?request_path=%2F", current_user: ... (pow) lib/extensions/email_confirmation/phoenix/controllers/controller_callbacks.ex:56: PowEmailConfirmation.Phoenix.ControllerCallbacks.send_confirmation_email/2 (pow) lib/extensions/email_confirmation/phoenix/controllers/controller_callbacks.ex:39: PowEmailConfirmation.Phoenix.ControllerCallbacks.halt_unconfirmed/3 (elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3 (pow) lib/pow/phoenix/controllers/controller.ex:88: Pow.Phoenix.Controller.action/3 (pow) lib/pow/phoenix/controllers/session_controller.ex:1: Pow.Phoenix.SessionController.action/2 (pow) lib/pow/phoenix/controllers/session_controller.ex:1: Pow.Phoenix.SessionController.phoenix_controller_pipeline/2 (user_profile_manager) lib/user_profile_manager_web/endpoint.ex:1: UserProfileManagerWeb.Endpoint.instrument/4 (phoenix) lib/phoenix/router.ex:278: Phoenix.Router.call/1 (user_profile_manager) lib/user_profile_manager_web/endpoint.ex:1: UserProfileManagerWeb.Endpoint.plug_builder_call/2 (user_profile_manager) lib/plug/debugger.ex:122: UserProfileManagerWeb.Endpoint."call (overridable 3)"/2 (user_profile_manager) lib/user_profile_manager_web/endpoint.ex:1: UserProfileManagerWeb.Endpoint.call/2 (plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4 (cowboy) /home/nar/mena_playground/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4

I see that this pow_email_confirmation_confirmation_url function is called, but I don't see any implementation for it in the 1.0.0-rc4 version and the README doesn't mention that I need to implement it either. I see that the e62374bf15acd2994293ab396b7efe62ede488f1 commit changed this in the extension, but I don't know how to get the latest version. How do I get it? I added {:pow, "~> 1.0.0-rc.4"} to mix.exs.

danschultzer commented 5 years ago

The extension routes are missing. Did you set up router.ex with pow_extension_routes()?

defmodule MyAppWeb.Router do
  use MyAppWeb, :router
  use Pow.Phoenix.Router
  use Pow.Extension.Phoenix.Router, otp_app: :my_app

  # ...

  scope "/" do
    pipe_through :browser

    pow_routes()
    pow_extension_routes()
  end

  # ...
end
danschultzer commented 5 years ago

Reference: https://github.com/danschultzer/pow#add-extensions-support

NAR commented 5 years ago

Yes, I did add the extension routes.

danschultzer commented 5 years ago

Did you change :otp_app config so it reads use Pow.Extension.Phoenix.Router, otp_app: :user_profile_manager, and do you Pow configuration look like config : user_profile_manager, :pow,?

I think this is what's missing. You can also do mix clean to ensure that the extension routes are loaded and compiled with your app.

danschultzer commented 5 years ago

Hey @NAR, did you solve this?

danschultzer commented 5 years ago

I'll close this for now :smile:

zerotao commented 2 years ago

Did you change :otp_app config so it reads use Pow.Extension.Phoenix.Router, otp_app: :user_profile_manager, and do you Pow configuration look like config : user_profile_manager, :pow,?

I think this is what's missing. You can also do mix clean to ensure that the extension routes are loaded and compiled with your app.

I was having the same issue, this is what I missed. Thanks!