janko / rodauth-rails

Rails integration for Rodauth authentication framework
https://github.com/jeremyevans/rodauth
MIT License
571 stars 40 forks source link

Optionally pass config name to RodauthMailer methods so @email_link includes the config prefix #103

Closed holdenhinkle closed 2 years ago

holdenhinkle commented 2 years ago

I created an admin account configuration like this:

class RodauthAdmin < RodauthBase # inherit common settings
  configure do
    # List of authentication features that are loaded.
    prefix "/admin"
  end

And the verification email link that was generated upon account creation didn't include /admin in the path.

Currently, there doesn't seem to be a way to pass in configuration names (like :admin) to methods in RodauthMailer that can be used to call #RodauthApp.rodauth so the correct path for the configuration is generated.

I quickly made the following changes to the app/mailers/rodauth_mailer.rb. There might be a better way to do this.

I'm posting this as a draft for your consideration. I'm happy to help contribute to this project in any way I can.

janko commented 2 years ago

Thanks for the pull request. That's a valid point, I agree it would be useful to be able to just move mailer hooks into the base configuration, and have it automatically work with multiple configurations.

I was wondering whether it wouldn't be better to make it a first argument, given that it's something passed into every mailer method, though I don't know if Ruby supports the first argument being optional 🤔

janko commented 2 years ago

BTW, you can access the configuration name via self.class.configuration_name inside the auth method blocks.