Skip to content

Commit

Permalink
Recommend retrieving the auth class through the Rodauth app
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Feb 12, 2024
1 parent 316a951 commit d87fa19
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ $ bundle add rodauth-model
The model mixin is built by calling `Rodauth::Model(...)` with the Rodauth auth class, and included into the account model:

```rb
require "rodauth"
require "rodauth/model" # require before enabling any authentication features

class RodauthMain < Rodauth::Auth
configure do
class RodauthApp < Roda
plugin :rodauth do
# ...
end
end
```
```rb
class Account < ActiveRecord::Base # Sequel::Model
include Rodauth::Model(RodauthMain)
include Rodauth::Model(RodauthApp.rodauth)
end
```

Expand Down Expand Up @@ -76,10 +75,10 @@ By default, all associations are configured to be deleted when the associated ac

```rb
# don't auto-delete associations when account model is deleted (Active Record)
Rodauth::Model(RodauthMain, association_options: { dependent: nil })
Rodauth::Model(RodauthApp.rodauth, association_options: { dependent: nil })

# require authentication audit logs to be eager loaded before retrieval (Sequel)
Rodauth::Model(RodauthMain, association_options: -> (name) {
Rodauth::Model(RodauthApp.rodauth, association_options: -> (name) {
{ forbid_lazy_load: true } if name == :authentication_audit_logs
})
```
Expand Down Expand Up @@ -148,7 +147,7 @@ It's possible to register multiple associations for the same Rodauth feature.

```rb
class Account < ActiveRecord::Base
include Rodauth::Model(RodauthMain)
include Rodauth::Model(RodauthApp.rodauth)

def mfa_enabled?
otp_key || (sms_code && sms_code.num_failures.nil?) || recovery_codes.any?
Expand All @@ -160,7 +159,7 @@ end

```rb
class Account < ActiveRecord::Base
include Rodauth::Model(RodauthMain)
include Rodauth::Model(RodauthApp.rodauth)

scope :otp_setup, -> { where(otp_key: OtpKey.all) }
scope :sms_codes_setup, -> { where(sms_code: SmsCode.where(num_failures: nil)) }
Expand Down

0 comments on commit d87fa19

Please sign in to comment.