Programming Phoenix 1.4 error undefined func authenticate_user

Hi everyone,

I have the following error:

** (CompileError) lib/rumbl_web/controllers/user_controller.ex:1: undefined function authenticate_user/2
    (elixir) src/elixir_locals.erl:108: :elixir_locals."-ensure_no_undefined_local/3-lc$^0/1-0-"/2
    (elixir) src/elixir_locals.erl:109: anonymous fn/3 in :elixir_locals.ensure_no_undefined_local/3
    (stdlib) erl_eval.erl:680: :erl_eval.do_apply/6

This error occurs at page 104
What I did already:

  • Checked to see if i have a misspelling of the function didn’t find any(using vscode search to search in the whole directory project)

  • Then accessed the source code of programming phoenix the relationship folder look at
    lib/rumblweb/controllers: user_controller.ex and auth.ex , no difference.

Am I allowed to upload my code to github to see what the problem is?

Because i really can’t find it.

Thanks in advance

To make it work You need to modify your endpoint… like this

  def controller do
    quote do
      use Phoenix.Controller, namespace: RumblWeb

      import Plug.Conn
      import RumblWeb.Gettext
      import RumblWeb.Auth, only: [authenticate_user: 2]
      alias RumblWeb.Router.Helpers, as: Routes
    end
  end

This line is important…

import RumblWeb.Auth, only: [authenticate_user: 2]

2 Likes

That did it

So does this import RumblWeb.Auth, only: [authenticate_user: 2] allows all the controllers to share this function?

Yes, I think You missed the part in the book where it is mentionned.

No I just wanted to make sure that i understood what it does.

Thanks @kokolegorille