riverrun / phauxth

Not actively maintained - Authentication library for Phoenix, and other Plug-based, web applications
409 stars 21 forks source link

Absinthe documentation possibly incorrect #77

Closed QuinnWilton closed 6 years ago

QuinnWilton commented 6 years ago

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?

riverrun commented 6 years ago

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.

riverrun commented 6 years ago

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.

riverrun commented 6 years ago

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