Skip to content

Commit dd13f53

Browse files
RenzoMinelliclaude
andcommitted
fix: narrow scope change to login_with_passkey_form_for only
Creation form helpers shouldn't scope fields under the Devise resource since those fields (like :name) are passkey/security key attributes, not account attributes. Only login_with_passkey_form_for needs the scope so that f.check_box :remember_me generates account[remember_me]. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent e7dfe78 commit dd13f53

6 files changed

Lines changed: 13 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
### Fixed
3838

3939
- Fix form helpers (`passkey_creation_form_for`, `login_with_passkey_button`, `security_key_creation_form_for`, `login_with_security_key_button`) to accept a `resource_name` instead of requiring the `resource` object from the view context. [#114](https://github.com/cedarcode/devise-webauthn/pull/114) [@RenzoMinelli]
40-
- BREAKING!: Scope form helpers to the Devise resource so that form builder fields (e.g. `f.check_box :remember_me`) are properly namespaced under the resource (e.g. `account[remember_me]`). Controllers now read `:name` from scoped params (`params.dig(resource_name, :name)`) instead of `params[:name]`. [#134](https://github.com/cedarcode/devise-webauthn/pull/134) [@RenzoMinelli]
40+
- Scope `login_with_passkey_form_for` to the Devise resource so that form builder fields (e.g. `f.check_box :remember_me`) are properly namespaced (e.g. `account[remember_me]`). [#134](https://github.com/cedarcode/devise-webauthn/pull/134) [@RenzoMinelli]
4141

4242
## [v0.3.1](https://github.com/cedarcode/devise-webauthn/compare/v0.3.0...v0.3.1/) - 2026-02-10
4343

app/controllers/devise/passkeys_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def verify_and_save_passkey(passkey_from_params)
4747

4848
resource.passkeys.create(
4949
external_id: passkey_from_params.id,
50-
name: params.dig(resource_name, :name),
50+
name: params[:name],
5151
public_key: passkey_from_params.public_key,
5252
sign_count: passkey_from_params.sign_count
5353
)

app/controllers/devise/second_factor_webauthn_credentials_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def verify_and_save_security_key(security_key_from_params)
5656

5757
resource.second_factor_webauthn_credentials.create(
5858
external_id: security_key_from_params.id,
59-
name: params.dig(resource_name, :name),
59+
name: params[:name],
6060
public_key: security_key_from_params.public_key,
6161
sign_count: security_key_from_params.sign_count
6262
)

lib/devise/webauthn/helpers/credentials_helper.rb

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ module Devise
44
module Webauthn
55
module CredentialsHelper
66
def passkey_creation_form_for(resource_or_resource_name, **options, &block)
7-
scope = Devise::Mapping.find_scope!(resource_or_resource_name)
8-
97
form_with(
10-
**options, scope: scope, url: passkeys_path(resource_or_resource_name), method: :post
8+
**options, url: passkeys_path(resource_or_resource_name), method: :post
119
) do |f|
1210
tag.webauthn_create(data: { options_url: passkey_registration_options_path(resource_or_resource_name) }) do
13-
concat hidden_field_tag(:public_key_credential, nil, data: { webauthn_target: "response" })
11+
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
1412
concat capture(f, &block)
1513
end
1614
end
@@ -30,31 +28,26 @@ def login_with_passkey_form_for(resource_or_resource_name, **options, &block)
3028
end
3129

3230
def security_key_creation_form_for(resource_or_resource_name, **options, &block)
33-
scope = Devise::Mapping.find_scope!(resource_or_resource_name)
34-
3531
form_with(
36-
**options, scope: scope, url: second_factor_webauthn_credentials_path(resource_or_resource_name),
37-
method: :post
32+
**options, url: second_factor_webauthn_credentials_path(resource_or_resource_name), method: :post
3833
) do |f|
3934
tag.webauthn_create(
4035
data: { options_url: security_key_registration_options_path(resource_or_resource_name) }
4136
) do
42-
concat hidden_field_tag(:public_key_credential, nil, data: { webauthn_target: "response" })
37+
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
4338
concat capture(f, &block)
4439
end
4540
end
4641
end
4742

4843
def login_with_security_key_form_for(resource_or_resource_name, **options, &block)
49-
scope = Devise::Mapping.find_scope!(resource_or_resource_name)
50-
5144
form_with(
52-
**options, scope: scope, url: two_factor_authentication_path(resource_or_resource_name), method: :post
45+
**options, url: two_factor_authentication_path(resource_or_resource_name), method: :post
5346
) do |f|
5447
tag.webauthn_get(data: {
5548
options_url: security_key_authentication_options_path(resource_or_resource_name)
5649
}) do
57-
concat hidden_field_tag(:public_key_credential, nil, data: { webauthn_target: "response" })
50+
concat f.hidden_field(:public_key_credential, data: { webauthn_target: "response" })
5851
concat capture(f, &block)
5952
end
6053
end

spec/requests/devise/passkeys_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
assert_difference("user.passkeys.count", 1) do
4747
post account_passkeys_path, params: {
4848
public_key_credential: credential.to_json,
49-
account: { name: "My Passkey" }
49+
name: "My Passkey"
5050
}
5151
end
5252

@@ -68,7 +68,7 @@
6868
assert_difference("user.passkeys.count", 0) do
6969
post account_passkeys_path, params: {
7070
public_key_credential: invalid_credential.to_json,
71-
account: { name: "My Passkey" }
71+
name: "My Passkey"
7272
}
7373
end
7474

spec/requests/devise/second_factor_webauthn_credentials_controller_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
assert_difference("user.second_factor_webauthn_credentials.count", 1) do
5757
post account_second_factor_webauthn_credentials_path, params: {
5858
public_key_credential: credential.to_json,
59-
account: { name: "My Security Key" }
59+
name: "My Security Key"
6060
}
6161
end
6262

@@ -78,7 +78,7 @@
7878
assert_difference("user.second_factor_webauthn_credentials.count", 0) do
7979
post account_second_factor_webauthn_credentials_path, params: {
8080
public_key_credential: invalid_credential.to_json,
81-
account: { name: "My Security Key" }
81+
name: "My Security Key"
8282
}
8383
end
8484

0 commit comments

Comments
 (0)