aaronrenner / phx_gen_auth

An authentication system generator for Phoenix 1.5 applications.
774 stars 56 forks source link

assign @current_user not available in eex template. #114

Closed conradwt closed 3 years ago

conradwt commented 3 years ago

After following the instructions within the README.md, I'm seeing the following error message when navigating to the landing page:

ArgumentError at GET /
assign @current_user not available in eex template.

Please make sure all proper assigns have been set. If this
is a child template, ensure assigns are given explicitly by
the parent template as they are not automatically forwarded.

Available assigns: [:conn, :deprecated_module_template, :inner_content, :movies, :view_module, :view_template]

Note: I'm not sure where @current_user is being defined here.

➜ elixir -v
Erlang/OTP 23 [erts-11.1.8] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]

Elixir 1.11.2 (compiled with Erlang/OTP 23)
➜ mix phx        
Phoenix v1.5.8

mix.exs (deps)

  defp deps do
    [
      {:bcrypt_elixir, "~> 2.0"},
      {:phoenix, "~> 1.5.8"},
      {:phoenix_ecto, "~> 4.1"},
      {:ecto_sql, "~> 3.4"},
      {:postgrex, ">= 0.0.0"},
      {:phoenix_html, "~> 2.11"},
      {:phoenix_live_reload, "~> 1.2", only: :dev},
      {:phoenix_live_dashboard, "~> 0.4"},
      {:telemetry_metrics, "~> 0.4"},
      {:telemetry_poller, "~> 0.4"},
      {:gettext, "~> 0.11"},
      {:jason, "~> 1.0"},
      {:plug_cowboy, "~> 2.0"},
      {:phx_gen_auth, "~> 0.6", only: [:dev], runtime: false}
    ]
  end
josevalim commented 3 years ago

This means the route you are trying to access is not running the plugs generated by mix phx.gen.auth. Make sure the plugs are in our pipeline and that the routes are invoking the relevant pipelines. Thanks.

conradwt commented 3 years ago

@josevalim After creating a new Phoenix project with mix phx.gen.auth, things work as expected. However, I was able to determine that the original project was missing fetch_current_user plug after comparing it against the new project. Thus, this issue can be closed.