Skip to content

Commit

Permalink
Allow define extra fields for sign up (#36)
Browse files Browse the repository at this point in the history
* feat: allow define extra fields for sign up

* doc: update readme
  • Loading branch information
Plus17 committed Dec 27, 2023
1 parent 7995136 commit f220683
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Devise.setup do |config|

# Sign up
api.sign_up.enabled = true
api.sign_up.extra_fields = []

# Authorization
api.authorization.key = 'Authorization'
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/devise/api/tokens_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def refresh
private

def sign_up_params
params.permit(*resource_class.authentication_keys,
params.permit(*Devise.api.config.sign_up.extra_fields, *resource_class.authentication_keys,
*::Devise::ParameterSanitizer::DEFAULT_PERMITTED_ATTRIBUTES[:sign_up]).to_h
end

Expand Down
1 change: 1 addition & 0 deletions lib/devise/api/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Configuration

setting :sign_up, reader: true do
setting :enabled, default: true, reader: true
setting :extra_fields, default: [], reader: true
end

setting :authorization, reader: true do
Expand Down
4 changes: 4 additions & 0 deletions spec/devise/api/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
it 'enabled is true' do
expect(config.sign_up.enabled).to eq true
end

it 'extra_fields is an empty array' do
expect(config.sign_up.extra_fields).to eq []
end
end

context 'authorization' do
Expand Down

0 comments on commit f220683

Please sign in to comment.