解决使用devise_token_auth和active_model_serializers发行多个用户模型的问题? [英] Work around for issue multiple user models with devise_token_auth and active_model_serializers?

查看:86
本文介绍了解决使用devise_token_auth和active_model_serializers发行多个用户模型的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用非用户模型(管理员和管理员)登录时,多个用户模型(用户,管理员和管理员)与devise_token_auth的组合无法成功设置响应头(uid,令牌等);

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.

原因似乎是active_model_serializers / lib / action_controller / serialization.rb:18中的默认serialization_scope(:current_user)。

The cause looks to be the default serialization_scope (:current_user) in active_model_serializers/lib/action_controller/serialization.rb:18.

是否可以设置serialization_scope,还是需要覆盖控制器?

Is there a way to set the serialization_scope, or do I need to override the controllers?

环境:


  • Rails 4.2.6

  • AMS 10.3

  • devise_token_auth 1.38

推荐答案

我目前的解决方法是在如下所示的覆盖控制器中设置作用域。感觉很脆弱,但可以正常工作

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

这篇关于解决使用devise_token_auth和active_model_serializers发行多个用户模型的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆