Closed Lazarus404 closed 4 years ago
Dagnabbit. I found the answer from my own questioning :)
For those that read this with the same issue, you need to add halt
to your Error Handler. For instance:
defmodule MyApp.AuthErrorHandler do
import Plug.Conn
@behaviour Guardian.Plug.ErrorHandler
@impl Guardian.Plug.ErrorHandler
def auth_error(conn, {type, reason}, _opts) do
body = Poison.encode!(%{message: to_string(type)})
conn
|> put_resp_content_type("application/json")
|> send_resp(401, body)
|> halt()
end
end
Okay, so, bearing in mind I'm upgrading from 0.14 to 2.0, so I may be doing something wrong. However, I have a permissions check at the top of each controller (different permissions for different actions). This may look like:
Now, in the
:create
action, it might look like:However, when running my test:
I see the unauthorised error printed in the console, but then the action gets run, anyway:
What I would expect is for the
Permission
check to halt thePlug
stack. Do I have to add anything additional to thePermission
call, perhaps?