Module: BetterAuth::Hanami::Routing

Defined in:
lib/better_auth/hanami/routing.rb

Constant Summary collapse

HTTP_METHODS =
%i[get post put patch delete options].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
# File 'lib/better_auth/hanami/routing.rb', line 8

def self.included(base)
  base.extend(self)
end

Instance Method Details

#better_auth(auth: nil, at: BetterAuth::Configuration::DEFAULT_BASE_PATH) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/better_auth/hanami/routing.rb', line 12

def better_auth(auth: nil, at: BetterAuth::Configuration::DEFAULT_BASE_PATH)
  mount_path = normalize_better_auth_mount_path(at)
  auth ||= BetterAuth::Hanami.auth(base_path: mount_path)
  app = BetterAuth::Hanami::MountedApp.new(auth, mount_path: mount_path)

  HTTP_METHODS.each do |method_name|
    public_send(method_name, mount_path, to: app)
    public_send(method_name, "#{mount_path}/*path", to: app)
  end
end