Pow: POW custom routes don't seem to work?

Created on 3 Mar 2019  路  12Comments  路  Source: danschultzer/pow

In the README.md it references custom routes that can be taken after actions. However, they all seem to be ignored and it just does default behaviours. Am I doing something wrong?

defmodule NfdWeb.Pow.Routes do
  use Pow.Phoenix.Routes
  alias NfdWeb.Router.Helpers, as: Routes

  def after_sign_out_path(conn), do: Routes.page_path(conn, :home)
  def after_sign_in_path(conn), do: Routes.dashboard_path(conn, :dashboard)
  def after_registration_path(conn), do: Routes.page_path(conn, :confirm_email_begin)
  def user_not_authenticated_path(conn), do: Routes.pow_session_path(conn, :new)
  def after_user_deleted_path(conn), do: Routes.page_path(conn, :home)
end

My config:

config :nfd, :pow,
  user: Nfd.Users.User,
  repo: Nfd.Repo,
  extensions: [PowResetPassword, PowEmailConfirmation],
  controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks,
  mailer_backend: NfdWeb.PowMailer,
  routes_backend: NfdWeb.Pow.Routes,
  web_mailer_module: NfdWeb,
  web_module: NfdWeb
bug

Most helpful comment

That's fine, thank you very much for all your help, I know running a library is hard, but I want to let you know that thousands of people use it everyday and it's just fantastic :)

All 12 comments

Configuration looks right. How does your phoenix endpoint module look?

This is the plug in endpoint.ex

  plug Pow.Plug.Session, 
    otp_app: :nfd,
    repo: Nfd.Repo, # not sure
    user: Nfd.Users.User, # not sure
    web_module: NfdWeb # not sure

You only need to have this:

 plug Pow.Plug.Session,  otp_app: :nfd

The config will fallback to to what you define in config :nfd, :pow

Can you try restart the app just to be sure that it's not just the config that hasn't been loaded properly?

I've reset and changed the plug reference to the above in endpoint.

It still appears to be following the normal flow.

When I register a new user, it goes back to the session/new template, as opposed to the confirm_email_begin route I've defined. I've also checked the router to see if it is set, and it is.

`
router.ex
scope "/", NfdWeb do
pipe_through :browser
get "/confirm_email_begin", PageController, :confirm_email_begin

`

page_controller.ex

def confirm_email_begin(conn, _params) do current_user = Pow.Plug.current_user(conn) conn |> put_flash(:user_email, current_user.email) |> render("confirm_email_begin.html") end
templates/page/confirm_email_begin.html.eex

So it appears the template is in all the right places.

Also having a look at the console, it doesn't seem to attempt to go to confirm_email begin.html.eex

[info] Sent 302 in 2574ms [info] GET /session/new
is the next place it goes. straight after sending the confirmation email.

Oh yeah, the email confirmation extension halts the connection before after_registration_path is reached:

https://github.com/danschultzer/pow/blob/db60379090191651254aed0b05ee93c3c97628e0/lib/extensions/email_confirmation/phoenix/controllers/controller_callbacks.ex#L46

It probably makes more sense to call after_registration_path, since if the email confirmation extension is enabled, it'll always prevent after_registration_path to be called. I'll look at this tomorrow when I got time!

You can try out #119, by pulling the github branch email-confirmation-redirects. It should fix it, but I'll have to check it later to be sure this fix makes sense.

That's fine, thank you very much for all your help, I know running a library is hard, but I want to let you know that thousands of people use it everyday and it's just fantastic :)

Thanks!

I think the branch is ready, but I want to confirm with you that it works as expected. Can you try out the branch by updating mix.exs with this:

{:pow, github: "danschultzer/pow", branch: "email-confirmation-redirects"}

I'll merge it in if it works for you.

@danschultzer Sure, thank you for that. I won't be able to get back straight away now that the work week has started, maybe over the next two days, so sorry if there's a big delay :)

@danschultzer Apologises, things have been crazy at work, but I promise I haven't forgotten about this! Will try and test it over the weekend :)

No problem!

@danschultzer Everything appears to be working fine :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

danschultzer picture danschultzer  路  5Comments

th31nitiate picture th31nitiate  路  5Comments

joepstender picture joepstender  路  6Comments

danschultzer picture danschultzer  路  6Comments

liamwhite picture liamwhite  路  6Comments