Class: HasSecurePasskey::Recovery

Inherits:
Object
  • Object
show all
Defined in:
lib/has_secure_passkey/recovery.rb

Instance Method Summary collapse

Constructor Details

#initialize(model:, params:) ⇒ Recovery



2
3
4
5
# File 'lib/has_secure_passkey/recovery.rb', line 2

def initialize(model:, params:)
  @model = model
  @params = params
end

Instance Method Details

#runObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/has_secure_passkey/recovery.rb', line 7

def run
  old_passkeys = authenticatable.passkeys.to_a

  ActiveRecord::Base.transaction do
    (authenticatable.update(webauthn_id:) &&
      authenticatable.add_passkey(params:) &&
      old_passkeys.all?(&:destroy) && authenticatable) ||
    raise(ActiveRecord::Rollback)
  end
end