Module: BetterAuth::Roda
- Defined in:
- lib/better_auth/roda.rb,
lib/better_auth/roda/version.rb,
lib/better_auth/roda/migration.rb,
lib/better_auth/roda/mounted_app.rb,
lib/better_auth/roda/configuration.rb
Defined Under Namespace
Modules: Migration
Classes: Configuration, MountedApp
Constant Summary
collapse
- VERSION =
"0.10.0"
Class Method Summary
collapse
Class Method Details
.app_config_path(path = nil) ⇒ Object
42
43
44
|
# File 'lib/better_auth/roda.rb', line 42
def app_config_path(path = nil)
path || BetterAuth::Env.get("BETTER_AUTH_CONFIG") || "config/better_auth.rb"
end
|
.auth(overrides = nil) ⇒ Object
29
30
31
32
33
34
|
# File 'lib/better_auth/roda.rb', line 29
def auth(overrides = nil)
options = configuration.to_auth_options
return @auth ||= BetterAuth.auth(options) if overrides.nil? || overrides.empty?
BetterAuth.auth(options.merge(overrides))
end
|
.configuration ⇒ Object
14
15
16
|
# File 'lib/better_auth/roda.rb', line 14
def configuration
@configuration ||= Configuration.new
end
|
18
19
20
21
22
|
# File 'lib/better_auth/roda.rb', line 18
def configure
yield configuration
@auth = nil
self
end
|
.default_config_template ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/better_auth/roda.rb', line 63
def default_config_template
<<~RUBY
# frozen_string_literal: true
require "better_auth/roda"
BetterAuth::Roda.configure do |config|
config.secret = BetterAuth::Env.fetch("BETTER_AUTH_SECRET", "change-me-roda-secret-12345678901234567890")
config.base_url = BetterAuth::Env.get("BETTER_AUTH_URL")
config.base_path = "/api/auth"
config.database = ->(options) do
case BetterAuth::Env.fetch("BETTER_AUTH_DATABASE_DIALECT", "postgres")
when "postgres", "postgresql"
BetterAuth::Adapters::Postgres.new(options, url: ENV.fetch("DATABASE_URL"))
when "mysql"
BetterAuth::Adapters::MySQL.new(options, url: ENV.fetch("DATABASE_URL"))
when "sqlite", "sqlite3"
BetterAuth::Adapters::SQLite.new(options, path: ENV.fetch("DATABASE_URL", "db/better_auth.sqlite3"))
else
raise "Unsupported BETTER_AUTH_DATABASE_DIALECT for better_auth-roda"
end
end
config.email_and_password = {
enabled: true
}
config.plugins = []
end
RUBY
end
|
.load_app_config(path = nil) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/better_auth/roda.rb', line 46
def load_app_config(path = nil)
config_path = app_config_path(path)
return false unless File.exist?(config_path)
load config_path
true
end
|
.load_app_config!(path = nil) ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/better_auth/roda.rb', line 54
def load_app_config!(path = nil)
config_path = app_config_path(path)
return true if load_app_config(config_path)
raise ArgumentError,
"Better Auth Roda config not found at #{config_path.inspect}. " \
"Run `rake better_auth:install` or set BETTER_AUTH_CONFIG to a shared config file."
end
|
.migration_configuration ⇒ Object
36
37
38
39
40
|
# File 'lib/better_auth/roda.rb', line 36
def migration_configuration
options = configuration.to_auth_options
options[:secret] ||= BetterAuth::Configuration::DEFAULT_SECRET
BetterAuth::Configuration.new(options)
end
|
.reset! ⇒ Object
24
25
26
27
|
# File 'lib/better_auth/roda.rb', line 24
def reset!
@configuration = nil
@auth = nil
end
|