Work around for issue multiple user models with devise_token_auth and active_model_serializers?

自闭症网瘾萝莉.ら 提交于 2020-02-05 04:08:13

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!