Skip to content
Janko Marohnić edited this page Dec 22, 2023 · 5 revisions

Feature

If you want to develop custom Rodauth extensions as part of your Rails app, it's recommended to put it in lib/rodauth/<feature_name>.rb, and require it explicitly in your Rodauth configuration file. For example:

# lib/rodauth/ldap.rb
module Rodauth
  Feature.define(:ldap, :Ldap) do
    def require_bcrypt?
      false
    end

    def password_match?(password)
      SimpleLdapAuthenticator.valid?(account[:email], password)
    end
  end
end
# app/misc/rodauth_main.rb
require "rodauth/ldap"

class RodauthMain < Rodauth::Rails::Auth
  configure do
    enable :login, :create_account, ..., :ldap
  end
end

If config.autoload_lib is not used, the feature code won't be reloaded in development. If using config.autoload_lib, the rodauth/ldap.rb directory will satisfy Zeitwerk naming requirements during eager loading, because the feature definition will define a Rodauth::Ldap constant, while the explicit require will ensure the feature code is correctly reloaded in development.

Module

An simpler alternative to a Rodauth feature is a plain module that you can include into your Rodauth configuration:

# app/misc/rodauth_ldap.rb
module RodauthLdap
  def require_bcrypt?
    false
  end

  def password_match?(password)
    SimpleLdapAuthenticator.valid?(account[:email], password)
  end
end
# app/misc/rodauth_main.rb
class RodauthMain < Rodauth::Rails::Auth
  include RodauthLdap

  configure do
    # ...
  end
end
Clone this wiki locally