Qwertie
Qwertie

Reputation: 6493

Adding extra fields to devise token auth user sign up

I have a signup form for devise-token-auth. I would like users to enter a username as well on the signup form. The username column exists in the database but the controller rejects it

Unpermitted parameter: :username

How can I extend the permitted parameters for signup in devise token auth?

Upvotes: 1

Views: 1392

Answers (2)

IlyaOsotov
IlyaOsotov

Reputation: 136

You need to set permitted params in your controller's action. Look this https://api.rubyonrails.org/classes/ActionController/Parameters.html

Upvotes: 0

Qwertie
Qwertie

Reputation: 6493

Looks like this works exactly the same as regular devise. The general idea can be found from this page

But specifically, add this to ApplicationController

before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters
  added_attrs = [:username, :email, :password, :password_confirmation]
  devise_parameter_sanitizer.permit :sign_up, keys: added_attrs
  devise_parameter_sanitizer.permit :account_update, keys: added_attrs
end

Upvotes: 1

Related Questions