Pow: User registration no longer showing "please confirm email" flash message when registering user.

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

Hi!

I suppose this question is more of a "if you're run into it, then happy to feel your thoughts.

Essentially, when I register a user, it will take you to the sign in page - however now it doesn't have the message to tell you to check your email to confirm. Does anyone have any possibly ideas why? I'm using all the standard routes and configurations.

Most helpful comment

You just need to change Routes.pow_session_path(@conn, :new) to Routes.pow_session_path(conn, :new).

For pow_email_confirmation_after_halted_registration_path/1, I haven't yet decided to merge in #141 yet. I think this may be managed with just the after_sign_in_path/1 and after_registration_path/1, so there may not be a need to add more code.

This is what you would set up currently to get it working:

defmodule SfusatoWeb.Pow.Routes do
  use Pow.Phoenix.Routes

  alias SfusatoWeb.Router.Helpers, as: Routes

  def after_registration_path(conn) do
    Routes.pow_session_path(conn, :new)
  end

  def after_sign_in_path(conn) do
    if Pow.Plug.current_user(conn),
      do: "/",
      else: Routes.pow_session_path(conn, :new)
  end
end

I have added the after_sign_in_path override too to show how you can check if the user is actually signed in or not before decided where to redirect to.

All 12 comments

How does the logic for printing info/error flash look like in layout.ex.html?

Oh, I have a suspicion that this may be because users are redirected to after_sign_in_path/1 now (#117 #119 #131). If the after_sign_in_path/1 is behind required auth, then it'll redirect to the session path and set the user_not_authenticated/1 error messages which by default is nil. Let me just test this out, and if it's true, then I'll see if I can fix this issue.

I've a proper fix for #117 up in #141. It'll default to the after_registration_path/1 like now, but you can override with a specific path for halted email confirmation instead:

defmodule MyAppWeb.Pow.Routes do
  use Pow.Phoenix.Routes
  use Pow.Extension.Phoenix.Routes,
    extension: [PowEmailConfirmation]

  alias MyAppWeb.Router.Helpers, as: Routes

  def pow_email_confirmation_after_halted_registration_path(conn), do: Routes.some_path(conn, :index)
end

This gives you full granular control, and may help you set up the routes so users are not redirected multiple times.

Hi Dan,

Sorry I couldn't get back soon, I was sleeping and it's morning now haha.

I've been looking into the issue and I think it might have something to possibly do with some code/library I've used (although I struggle to understand why or which one)?

I know I've added the {:recaptcha, ""} library, and when I git stash everything the message shows again. I've added a lot of template logic, but none of it touches any of the login/registration templates.

The odd thing is that the message still doesn't show when I comment absolutely everything out of the changes I've made, so I'm a bit baffled as to why it's not working.

I've just stashed everything and will iteratively start again. I'll update you if I find the code that's interfering.

Oh, and I wasn't even adding the :recaptcha library to the sign in form, it was for a completely different contact form.

Also, I have the flash/error inside the session/new template (and possibly the same for registration as well), rather than in the layout. It's been working so far, so I'm not sure if that's the issue.

    <p class="alert alert-info" role="alert"><%= get_flash(@conn, :info) %></p>
    <p class="alert alert-danger" role="alert"><%= get_flash(@conn, :error) %></p>

Does your root route at "/" require authentication?

It doesn't, no.

I've added most of the logic back after the git stash, including the recaptcha library and everything seems fine. Really odd.

Maybe it had something to do with mix.lock or something, but yeah, very odd.

Oh, that's really weird. I'll close this issue for now then, please do let me know if you experience the issue again, or figure out what caused it.

I've installed the PowEmailConfirmation extension and after a new registration, I've expected the user to be redirected to sessions/new with a Please confirm email flash message.

I'm redirected to the root page.

I'm following your fix above, but I get this compilation error:
== Compilation error in file lib/sfusato_web/pow/routes.ex == ** (CompileError) lib/sfusato_web/pow/routes.ex:4: module Pow.Extensions.Phoenix.Routes is not loaded and could not be found

Renaming to use Pow.Extension.Phoenix.Router, extension: [PowEmailConfirmation] seems to work, but there's no effect as I'm still redirected to /.

This is my routes.ex file:

defmodule SfusatoWeb.Pow.Routes do
  use Pow.Phoenix.Routes

  use Pow.Extension.Phoenix.Router,
    extension: [PowEmailConfirmation]

  alias SfusatoWeb.Router.Helpers, as: Routes

  def pow_email_confirmation_after_halted_registration_path(conn) do
    Routes.pow_session_path(@conn, :new)
  end
end

I've added the after_registration_path callback and this one seems to be called:

  def after_registration_path(conn) do
    Routes.pow_session_path(@conn, :new)
  end

but it results in this error:

UndefinedFunctionError at POST /registration
function nil.path/1 is undefined

Called with 1 arguments
"/session/new"

config.exs:

config :sfusato, :pow,
  user: Sfusato.Auth.User,
  repo: Sfusato.Repo,
  web_module: SfusatoWeb,
  routes_backend: SfusatoWeb.Pow.Routes,
  mailer_backend: Sfusato.Mailer.PowMailer,
  web_mailer_module: SfusatoWeb,
  extensions: [PowResetPassword, PowEmailConfirmation],
  controller_callbacks: Pow.Extension.Phoenix.ControllerCallbacks

endpoint.ex

  plug Pow.Plug.Session, otp_app: :sfusato

You just need to change Routes.pow_session_path(@conn, :new) to Routes.pow_session_path(conn, :new).

For pow_email_confirmation_after_halted_registration_path/1, I haven't yet decided to merge in #141 yet. I think this may be managed with just the after_sign_in_path/1 and after_registration_path/1, so there may not be a need to add more code.

This is what you would set up currently to get it working:

defmodule SfusatoWeb.Pow.Routes do
  use Pow.Phoenix.Routes

  alias SfusatoWeb.Router.Helpers, as: Routes

  def after_registration_path(conn) do
    Routes.pow_session_path(conn, :new)
  end

  def after_sign_in_path(conn) do
    if Pow.Plug.current_user(conn),
      do: "/",
      else: Routes.pow_session_path(conn, :new)
  end
end

I have added the after_sign_in_path override too to show how you can check if the user is actually signed in or not before decided where to redirect to.

Yiikes, I have no idea how I didn't spot the @ before conn. I must have copy-pasted that from the template. My bad.

Thank you. Everything works as expected.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

chevinbrown picture chevinbrown  路  6Comments

dweremeichik picture dweremeichik  路  7Comments

Kaquadu picture Kaquadu  路  4Comments

danschultzer picture danschultzer  路  3Comments

jung-hunsoo picture jung-hunsoo  路  3Comments