Skip to content

Commit 79d3e9c

Browse files
committed
rename param
1 parent 8573aa9 commit 79d3e9c

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ $ bin/rails generate devise:webauthn:views -v passkeys
145145
```
146146

147147
### Helper methods
148-
Devise::Webauthn provides helpers that can be used in your views. For example, for a resource named `user`, you can use the following helpers:
148+
Devise::Webauthn provides helpers that can be used in your views. These helpers accept either a resource name (e.g., `:user`) or a resource object (e.g., `@user`) as the first argument.
149+
150+
For example, for a resource named `user`, you can use the following helpers:
149151

150152
To add a button for logging in with passkeys:
151153
```erb

lib/devise/webauthn/helpers/credentials_helper.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,59 @@
44
module Devise
55
module Webauthn
66
module CredentialsHelper
7-
def passkey_creation_form_for(resource_name, form_classes: nil, &block)
7+
def passkey_creation_form_for(resource_or_resource_name, form_classes: nil, &block)
88
form_with(
9-
url: passkeys_path(resource_name),
9+
url: passkeys_path(resource_or_resource_name),
1010
method: :post,
1111
class: form_classes
1212
) do |f|
13-
tag.webauthn_create(data: { options_url: passkey_registration_options_path(resource_name) }) do
13+
tag.webauthn_create(data: { options_url: passkey_registration_options_path(resource_or_resource_name) }) do
1414
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
1515
concat capture(f, &block)
1616
end
1717
end
1818
end
1919

20-
def login_with_passkey_button_for(resource_name, text = nil, session_path:, button_classes: nil,
20+
def login_with_passkey_button_for(resource_or_resource_name, text = nil, session_path:, button_classes: nil,
2121
form_classes: nil, &block)
2222
form_with(
2323
url: session_path,
2424
method: :post,
2525
class: form_classes
2626
) do |f|
27-
tag.webauthn_get(data: { options_url: passkey_authentication_options_path(resource_name) }) do
27+
tag.webauthn_get(data: { options_url: passkey_authentication_options_path(resource_or_resource_name) }) do
2828
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
2929

3030
concat f.button(text, type: "submit", class: button_classes, &block)
3131
end
3232
end
3333
end
3434

35-
def security_key_creation_form_for(resource_name, form_classes: nil, &block)
35+
def security_key_creation_form_for(resource_or_resource_name, form_classes: nil, &block)
3636
form_with(
37-
url: second_factor_webauthn_credentials_path(resource_name),
37+
url: second_factor_webauthn_credentials_path(resource_or_resource_name),
3838
method: :post,
3939
class: form_classes
4040
) do |f|
4141
tag.webauthn_create(
42-
data: { options_url: security_key_registration_options_path(resource_name) }
42+
data: { options_url: security_key_registration_options_path(resource_or_resource_name) }
4343
) do
4444
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
4545
concat capture(f, &block)
4646
end
4747
end
4848
end
4949

50-
def login_with_security_key_button_for(resource_name, text = nil, button_classes: nil, form_classes: nil, &block)
50+
def login_with_security_key_button_for(resource_or_resource_name, text = nil, button_classes: nil,
51+
form_classes: nil, &block)
5152
form_with(
52-
url: two_factor_authentication_path(resource_name),
53+
url: two_factor_authentication_path(resource_or_resource_name),
5354
method: :post,
5455
class: form_classes
5556
) do |f|
56-
tag.webauthn_get(data: { options_url: security_key_authentication_options_path(resource_name) }) do
57+
tag.webauthn_get(data: {
58+
options_url: security_key_authentication_options_path(resource_or_resource_name)
59+
}) do
5760
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
5861
concat f.button(text, type: "submit", class: button_classes, &block)
5962
end

0 commit comments

Comments
 (0)