Open sumit20rai opened 6 years ago
@sumit20rai what do you mean by response.valid?
?
@MaicolBen sorry it was typo, i meant when i did @resource.valid?, it is coming true, so i don't have any validation errors also.
Weird, maybe the problem is the same as #1159. But you can log in with one model but not the other. I need to do further investigation
@sumit20rai, this might be caused by the default serialization_scope of current_user
. When json is rendered from the sessions_controller, for instance, it will call the helper method current_user
which will then wipe the access tokens if the mapping is incorrect.
I would be interested to see if this is your case. Can you check if you are calling the current_user
helper method when you attempt to sign in as an admin?
# lib/devise_token_auth/controllers/helpers.rb
def current_#{mapping}
binding.pry
puts __method__
...
end
I've got the same problem as @sumit20rai described, did anyone have found a solution?
ok, i don't know if this is the right way to fix this, but I did this, and it works:
class ApplicationController < ActionController::API
include DeviseTokenAuth::Concerns::SetUserByToken
before_action :configure_permitted_parameters, if: :devise_controller?
protected
# Extend sign_up parameters
# @see https://github.com/plataformatec/devise#strong-parameters
def configure_permitted_parameters
self.class.serialization_scope :view_context
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
end
end
setting the serialization_scope for devise controllers to :view_context
!
@Amrani I am using multi model and having the same problem. I can confirm that it calls the current_user
helper while I try to sign in as admin
@lpsBetty it works for me too. thanks for sharing!
I have setup devise_token_auth for multiple models( User and Admin). I am getting auth header for User sign in but not for admin sign in.
I also checked the @resource.valid? for Admin login and it is coming true. Any help guys?