I am using the new version of guardian for authentication which I have configured it works fine the only problem is when I want to display the current logged in username in my header.html.eex layout i.e
Here is my guardian plug to fetch the current user
defmodule Petronexus.SetCurrentUser do
def init(opts), do: opts
def call(conn, _opts) do
user = Guardian.Plug.current_resource(conn)
Plug.Conn.assign(conn, :current_user, user)
end
end
which I have added into my router.ex as
pipeline :login_required do
plug Petronexus.Auth.Pipeline
plug Petronexus.Plug.SetCurrentUser
end
The assign would either be passed to your template from the Controller, or from the View that back your page. What does the render call in the controller look like?
oooh yeah my bad I have 2 scopes in my router so I had not passed :login_required to one of them that was the reason. Silly mistake, I should be careful next time