13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/better_auth/roda/plugin.rb', line 13
def better_auth(at: BetterAuth::Configuration::DEFAULT_BASE_PATH, auth: nil, **overrides)
mount_path = normalize_better_auth_mount_path(at)
if mount_path == "/"
raise ArgumentError,
"better_auth mount path cannot be '/' (it would capture every request). " \
"Use a prefix such as #{BetterAuth::Configuration::DEFAULT_BASE_PATH.inspect}."
end
if opts[:better_auth_configured] && opts[:better_auth_owner].equal?(self)
raise ArgumentError, "better_auth is already configured for this app"
end
config = BetterAuth::Roda.configuration.copy
yield config if block_given?
config.base_path = mount_path
options = config.to_auth_options.merge(overrides).merge(base_path: mount_path)
auth_instance = auth || BetterAuth.auth(options)
opts[:better_auth_auth] = auth_instance
opts[:better_auth_mount_path] = mount_path
opts[:better_auth_mounted_app] = BetterAuth::Roda::MountedApp.new(auth_instance, mount_path: mount_path)
opts[:better_auth_owner] = self
opts[:better_auth_configured] = true
end
|