Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Something is overriding the render function on authentication failure #53

Open
setriva opened this issue Oct 15, 2016 · 3 comments
Open

Comments

@setriva
Copy link

setriva commented Oct 15, 2016

Hello,
What the title says: on authentication failure, the app renders "Authorization Failed", instead of the json I'm trying to render. Here is my code:

def create
    user = authenticate_session(session_params)
    if sign_in(user)
      render json: user, serializer: AuthenticationSerializer, root: :user
    else
      render json: { errors: 'Wrong email or password' }, status: :unauthorized
    end
  end

There is no problem when the user authenticates correctly, the problem is only when it fails.
Any suggestions?

Thanks!

@jsteiner
Copy link
Contributor

I think the issue is that Warden automatically captures 401 responses and forces it's own body. You should be able to override this with warden.custom_failure!: https://github.com/hassox/warden/blob/906edf86c6c31be917a921097031b89361d022e8/lib/warden/proxy.rb#L286

@halogenandtoast
Copy link
Owner

Given that this is warden territory, my question here is should Monban do anything about this, and if so, what?

@halogenandtoast
Copy link
Owner

I've decided it will probably just be best to add this to the documentation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants