Skip to content

Commit 8573aa9

Browse files
committed
send resource name always
1 parent d3e512a commit 8573aa9

6 files changed

Lines changed: 17 additions & 16 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,12 +149,12 @@ Devise::Webauthn provides helpers that can be used in your views. For example, f
149149

150150
To add a button for logging in with passkeys:
151151
```erb
152-
<%= login_with_passkey_button("Log in with passkeys", session_path: user_session_path) %>
152+
<%= login_with_passkey_button_for(:user, "Log in with passkeys", session_path: user_session_path) %>
153153
```
154154

155155
To add a passkeys creation form:
156156
```erb
157-
<%= passkey_creation_form_for(current_user) do |form| %>
157+
<%= passkey_creation_form_for(:user) do |form| %>
158158
<%= form.label :name, 'Passkey name' %>
159159
<%= form.text_field :name, required: true %>
160160
<%= form.submit 'Create Passkey' %>

app/views/devise/passkeys/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= passkey_creation_form_for(resource) do |form| %>
1+
<%= passkey_creation_form_for(resource_name) do |form| %>
22
<%= form.label :name, 'Passkey name' %>
33
<%= form.text_field :name, required: true %>
44
<%= form.submit 'Create Passkey' %>

app/views/devise/second_factor_webauthn_credentials/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<%= security_key_creation_form_for(resource) do |form| %>
1+
<%= security_key_creation_form_for(resource_name) do |form| %>
22
<%= form.label :name, 'Security Key name' %>
33
<%= form.text_field :name, required: true %>
44
<%= form.submit 'Create Security Key' %>

app/views/devise/sessions/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
</div>
2424
<% end %>
2525

26-
<%= login_with_passkey_button("Log in with passkeys", session_path: session_path(resource_name)) %>
26+
<%= login_with_passkey_button_for(resource_name, "Log in with passkeys", session_path: session_path(resource_name)) %>
2727

2828
<%= render "devise/shared/links" %>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<%= login_with_security_key_button('Use security key', resource: @resource) %>
1+
<%= login_with_security_key_button_for(resource_name, 'Use security key') %>

lib/devise/webauthn/helpers/credentials_helper.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
module Devise
55
module Webauthn
66
module CredentialsHelper
7-
def passkey_creation_form_for(resource, form_classes: nil, &block)
7+
def passkey_creation_form_for(resource_name, form_classes: nil, &block)
88
form_with(
9-
url: passkeys_path(resource),
9+
url: passkeys_path(resource_name),
1010
method: :post,
1111
class: form_classes
1212
) do |f|
13-
tag.webauthn_create(data: { options_url: passkey_registration_options_path(resource) }) do
13+
tag.webauthn_create(data: { options_url: passkey_registration_options_path(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(text = nil, session_path:, button_classes: nil, form_classes: nil, &block)
20+
def login_with_passkey_button_for(resource_name, text = nil, session_path:, button_classes: nil,
21+
form_classes: nil, &block)
2122
form_with(
2223
url: session_path,
2324
method: :post,
@@ -31,28 +32,28 @@ def login_with_passkey_button(text = nil, session_path:, button_classes: nil, fo
3132
end
3233
end
3334

34-
def security_key_creation_form_for(resource, form_classes: nil, &block)
35+
def security_key_creation_form_for(resource_name, form_classes: nil, &block)
3536
form_with(
36-
url: second_factor_webauthn_credentials_path(resource),
37+
url: second_factor_webauthn_credentials_path(resource_name),
3738
method: :post,
3839
class: form_classes
3940
) do |f|
4041
tag.webauthn_create(
41-
data: { options_url: security_key_registration_options_path(resource) }
42+
data: { options_url: security_key_registration_options_path(resource_name) }
4243
) do
4344
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
4445
concat capture(f, &block)
4546
end
4647
end
4748
end
4849

49-
def login_with_security_key_button(text = nil, resource:, button_classes: nil, form_classes: nil, &block)
50+
def login_with_security_key_button_for(resource_name, text = nil, button_classes: nil, form_classes: nil, &block)
5051
form_with(
51-
url: two_factor_authentication_path(resource),
52+
url: two_factor_authentication_path(resource_name),
5253
method: :post,
5354
class: form_classes
5455
) do |f|
55-
tag.webauthn_get(data: { options_url: security_key_authentication_options_path(resource) }) do
56+
tag.webauthn_get(data: { options_url: security_key_authentication_options_path(resource_name) }) do
5657
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
5758
concat f.button(text, type: "submit", class: button_classes, &block)
5859
end

0 commit comments

Comments
 (0)