Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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
like image 512
Boyd Avatar asked Nov 15 '25 05:11

Boyd


1 Answers

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
like image 149
Boyd Avatar answered Nov 17 '25 19:11

Boyd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!