riverrun/phauxth

Absinthe documentation possibly incorrect

Closed this issue · 3 comments

I'm not sure whether I was doing something wrong, but I wasn't able to get the token into the Absinthe context using the plug from the docs. Instead I needed to use the following plug:

defmodule AbsintheAuthenticatePlug do
  use Phauxth.Authenticate.Base

  def set_user(user, conn) do
    Absinthe.Plug.put_options(conn, context: %{token: %{current_user: user}})
  end
end

Compared to the following:

defmodule AbsintheAuthenticatePlug do
  use Phauxth.Authenticate.Base
  import Plug.Conn

  def set_user(user, conn) do
    put_private(conn, :absinthe, %{token: %{current_user: user}})
  end
end

I don't know all of the nuances that differentiate the two, but my version is more in line with the example plug from the Absinthe docs: https://hexdocs.pm/absinthe/context-and-authentication.html#content

Is it worth me changing the examples in the code to match this?

Sorry for the delay in getting back to you - made busy at the moment. I'll have a look at this issue now and get back to you soon.

It looks like Absinthe.Plug.put_options calls the put_private function, but before that, it makes sure to merge those changes with what is currently in the absinthe context - so it's a better version.

I'll update the docs now.

Version 1.2.7 now has the updated docs - thanks for reporting the issue.