Module: BetterAuth::APIKey::PluginFactory

Defined in:
lib/better_auth/api_key/plugin_factory.rb

Class Method Summary collapse

Class Method Details

.build(configurations = {}, options = nil) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/better_auth/api_key/plugin_factory.rb', line 8

def build(configurations = {}, options = nil)
  config = BetterAuth::APIKey::Configuration.normalize(configurations, options)
  BetterAuth::Plugin.new(
    id: "api-key",
    version: BetterAuth::APIKey::VERSION,
    hooks: {
      before: [
        {
          matcher: ->(ctx) { !!BetterAuth::APIKey::Session.header_config(ctx, config) },
          handler: ->(ctx) { BetterAuth::APIKey::Session.hook(ctx, config) }
        }
      ]
    },
    endpoints: {
      create_api_key: BetterAuth::APIKey::Routes::CreateAPIKey.endpoint(config),
      verify_api_key: BetterAuth::APIKey::Routes::VerifyAPIKey.endpoint(config),
      get_api_key: BetterAuth::APIKey::Routes::GetAPIKey.endpoint(config),
      update_api_key: BetterAuth::APIKey::Routes::UpdateAPIKey.endpoint(config),
      delete_api_key: BetterAuth::APIKey::Routes::DeleteAPIKey.endpoint(config),
      list_api_keys: BetterAuth::APIKey::Routes::ListAPIKeys.endpoint(config),
      delete_all_expired_api_keys: BetterAuth::APIKey::Routes::DeleteAllExpiredAPIKeys.endpoint(config)
    },
    schema: BetterAuth::APIKey::SchemaDefinition.schema(config, config[:schema]),
    error_codes: BetterAuth::APIKey::ERROR_CODES,
    options: config
  )
end