devise_token_auth icon indicating copy to clipboard operation
devise_token_auth copied to clipboard

Cannot override json response of authenticate_user!

Open manuel-burato opened this issue 10 years ago • 5 comments

Hi, I am making a REST API server. I have overridden all devise_token_auth resposes. The only one I can't override is from authenticate_user!

Looking the code, I saw that this function come from devise_token_auth/lib/devise_token_auth/controllers/helpers.rb (Line 32) and the response is did direcly from that code.

Is there any way to override this?

Thanks

manuel-burato avatar Mar 15 '16 18:03 manuel-burato

Hi, any progress on this? thanks

Alxzu avatar Apr 06 '16 00:04 Alxzu

+1

NetanelBasal avatar Apr 13 '16 14:04 NetanelBasal

+1

the-bass avatar Apr 14 '16 14:04 the-bass

You can overwrite this method for selected resource in controller that includes DeviseTokenAuth::Concerns::SetUserByToken.

For example:

class ApplicationController < ActionController::API
  include DeviseTokenAuth::Concerns::SetUserByToken

  private

  def authenticate_user!
    unless current_user
      return render json: {
        errors: ["You shall not pass!"]
      }, status: 401
    end
  end
end

daralbrecht avatar Apr 28 '16 13:04 daralbrecht

nice! that do the work Many thanks :)

manuel-burato avatar Apr 28 '16 20:04 manuel-burato