问题
The combination of multiple user models (User, Admin, and Master) with devise_token_auth does not successfully set the Response Headers (uid, token, etc.) upon login with non "User" models (Admin and Master); however, User model works.
The cause looks to be the default serialization_scope (:current_user) in active_model_serializers/lib/action_controller/serialization.rb:18.
Is there a way to set the serialization_scope, or do I need to override the controllers?
Environment:
- Rails 4.2.6
- AMS 10.3
- devise_token_auth 1.38
回答1:
My current work around was to set the scope in an overridden controller like below. This feels brittle, but it works
class Overrides::Master::SessionsController < DeviseTokenAuth::SessionsController
protected
def render_create_success
render json: {
data: resource_data(resource_json: @resource.token_validation_response)
}, scope: :current_master
end
end
来源:https://stackoverflow.com/questions/41011398/work-around-for-issue-multiple-user-models-with-devise-token-auth-and-active-mod