-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Token generation fails when user has incomplete data that is mandatory #938
Comments
Can you use the For example, on your model: validates :first_name, presence: true, on: :update_account And then in the part of your app that handles the user updates: user.save(context: :update_account) This way the validation won't be triggered by auth token updates or anything else unrelated to the user's actions. |
@lynndylanhurley I didn't know about context good to know, thanks for pointing this topic out, the problem I see using a custom |
So then are you suggesting that we save the user model using |
@lynndylanhurley yeah why not, do you know what are the implications/disadvantages of doing that? |
@heridev well, I think it's kind of bad practice to just not run validations at all on a save action by default as part of a library... I'm going to close this but reopen if you disagree and have a compelling case or examples to the contrary from other libs. |
As far as I know all the versions for
devise_token_auth
useself.save!
when a new token is generated withincreate_new_auth_token
, the problem with that occurs when you have custom validation rules, for instance:User schema:
Validation rule:
So any user created previously(before adding the validation rule) and that did not have
first_name
will have authentication problems because in every place that you invokecurrent_user
or those sort of helpers that internally callscreate_new_auth_token
will not create a valid token.Right now the way we solve this authentication issue for those kinds of users is skipping validation rules with the usage of an attr accessor, as an example:
Within the controller(eg: sessions_controller.rb)
and the other way is deactivating any validation rules overriding the original method
create_new_auth_token(client_id=nil)
and usingvalidate: false
:With something like this:
Do you guys know any other approach to solve these sort of issues?
The text was updated successfully, but these errors were encountered: