Skip to content

Instantly share code, notes, and snippets.

@hauptbenutzer
Created November 25, 2018 07:33
Show Gist options
  • Save hauptbenutzer/bcc528c622317aabf0b8c5ee1890c536 to your computer and use it in GitHub Desktop.
Save hauptbenutzer/bcc528c622317aabf0b8c5ee1890c536 to your computer and use it in GitHub Desktop.
Guardian VerifyHeader Wrapper
defmodule MyAppWeb.Guardian.VerifyHeader do
@moduledoc """
This is a wrapper for Guardian.Plug.VerifyHeader, the difference being that
we do not want the connection to be halted.
"""
@behaviour Plug
def init(opts), do: Guardian.Plug.VerifyHeader.init(opts)
def call(conn, opts) do
conn = Guardian.Plug.VerifyHeader.call(conn, opts)
# Since Guardian 1.x, the conn is automatically halted after being passed to the
# error handler. We do want it to reach the downstream plugs, so we'll unhalt it.
# see https://github.com/ueberauth/guardian/issues/401
%{conn | halted: false}
end
end
@Apelsinka223
Copy link

Apelsinka223 commented Nov 26, 2018

Good solution, but I added state to %{conn | halted: false, state: :unset}, to avoid Plug.Conn.AlreadySentError error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment