12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/better_auth/sinatra/extension.rb', line 12
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
warn "[better_auth-sinatra] better_auth is already configured for this app; the new configuration will be appended." if respond_to?(:better_auth_auth)
config = BetterAuth::Sinatra.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)
set :better_auth_auth, auth_instance
set :better_auth_mount_path, mount_path
use BetterAuth::Sinatra::MountedApp, -> { settings.better_auth_auth }, mount_path: mount_path
end
|