nejdetkadir / devise-api

The devise-api gem is a convenient way to add authentication to your Ruby on Rails application using the devise gem. It provides support for access tokens and refresh tokens, which allow you to authenticate API requests and keep the user's session active for a longer period of time on the client side
MIT License
152 stars 22 forks source link

Allow configuring additional fields for API registration #5

Closed nejdetkadir closed 8 months ago

nejdetkadir commented 1 year ago

The devise-api gem currently only allows for email and password fields during user registration through the API. It would be useful to have the ability to specify additional fields that are required or accepted during registration, such as name or address. This would provide more flexibility in terms of user registration through the API. It would be great if this feature could be added to the gem.

1gn0r4nd commented 1 year ago

Assuming you have an attribute 'name' and 'address' for your model 'user', you can do the following:

class Api::V1::Users::TokensController < Devise::Api::TokensController
    private
    def sign_up_params
      params.permit(:name, :address, *resource_class.authentication_keys,
                    *::Devise::ParameterSanitizer::DEFAULT_PERMITTED_ATTRIBUTES[:sign_up]).to_h
    end
end
nachosca commented 1 year ago

Hey @1gn0r4nd, I'm having the same issue. I tried that code and but it's still not working. I have some questions regarding this:

Sorry for the questions, I'm kind of new in RoR. Thanks in advance.