Class: BetterAuth::Rails::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/better_auth/rails/configuration.rb

Constant Summary collapse

AUTH_OPTION_NAMES =
%i[
  app_name
  base_url
  base_path
  secret
  database
  plugins
  trusted_origins
  rate_limit
  session
  account
  user
  verification
  advanced
  email_and_password
  password_hasher
  email_verification
  social_providers
  experimental
  secondary_storage
  database_hooks
  hooks
  on_api_error
  disabled_paths
  logger
].freeze
BLOCK_OPTION_NAMES =
%i[
  rate_limit
  session
  account
  user
  verification
  advanced
  email_and_password
  email_verification
  social_providers
  experimental
  database_hooks
  hooks
  on_api_error
].freeze

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



61
62
63
64
65
66
# File 'lib/better_auth/rails/configuration.rb', line 61

def initialize
  @base_path = BetterAuth::Configuration::DEFAULT_BASE_PATH
  @plugins = []
  @trusted_origins = []
  @database = ->(options) { ActiveRecordAdapter.new(options) }
end

Instance Method Details

#database_adapter=(adapter) ⇒ Object



68
69
70
71
72
73
74
75
# File 'lib/better_auth/rails/configuration.rb', line 68

def database_adapter=(adapter)
  case adapter&.to_sym
  when :active_record
    self.database = ->(options) { ActiveRecordAdapter.new(options) }
  else
    raise ArgumentError, "Unsupported database_adapter: #{adapter.inspect}. Use :active_record or assign a custom adapter with config.database = ..."
  end
end

#to_auth_optionsObject



77
78
79
80
81
82
83
84
85
# File 'lib/better_auth/rails/configuration.rb', line 77

def to_auth_options
  AUTH_OPTION_NAMES.each_with_object({}) do |name, options|
    value = public_send(name)
    next if value.nil?
    next if value.respond_to?(:empty?) && value.empty?

    options[name] = value
  end
end