Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User registration no longer showing "please confirm email" flash message when registering user. #140

Closed
dottjt opened this issue Mar 15, 2019 · 12 comments

Comments

@dottjt
Copy link

dottjt commented Mar 15, 2019

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.

@danschultzer
Copy link
Collaborator

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

@danschultzer
Copy link
Collaborator

danschultzer commented Mar 15, 2019

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.

@danschultzer
Copy link
Collaborator

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.

@dottjt
Copy link
Author

dottjt commented Mar 15, 2019

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.

@dottjt
Copy link
Author

dottjt commented Mar 15, 2019

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

@dottjt
Copy link
Author

dottjt commented Mar 15, 2019

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>

@danschultzer
Copy link
Collaborator

danschultzer commented Mar 15, 2019

Does your root route at "/" require authentication?

@dottjt
Copy link
Author

dottjt commented Mar 16, 2019

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.

@danschultzer
Copy link
Collaborator

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.

@sfusato
Copy link

sfusato commented Mar 31, 2019

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

@danschultzer
Copy link
Collaborator

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.

@sfusato
Copy link

sfusato commented Mar 31, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants