aaronrenner / phx_gen_auth

An authentication system generator for Phoenix 1.5 applications.
772 stars 55 forks source link

(RuntimeError) could not compile application #94

Closed dbi1 closed 4 years ago

dbi1 commented 4 years ago

Hi again,

after installing make I successfully installed / ran the auth generator, and have been playing around with the auth functionality via the UI.

I successfully registered a user and changed the associated email address. Then, after letting the page sit for a while I came back to it, tried to change the email address again (if I remember correctly), and got the following error:

** (RuntimeError) could not compile application: my_app.

You must restart your server after changing the following config or lib files:

  * mix.exs

    (phoenix 1.5.6) lib/phoenix/code_reloader/server.ex:211: Phoenix.CodeReloader.Server.mix_compile_unless_stale_config/1
    (phoenix 1.5.6) lib/phoenix/code_reloader/server.ex:75: anonymous fn/2 in Phoenix.CodeReloader.Server.handle_call/3
    (phoenix 1.5.6) lib/phoenix/code_reloader/server.ex:262: Phoenix.CodeReloader.Server.proxy_io/1
    (phoenix 1.5.6) lib/phoenix/code_reloader/server.ex:73: Phoenix.CodeReloader.Server.handle_call/3
    (stdlib 3.13.2) gen_server.erl:706: :gen_server.try_handle_call/4
    (stdlib 3.13.2) gen_server.erl:735: :gen_server.handle_msg/6
    (stdlib 3.13.2) proc_lib.erl:226: :proc_lib.init_p_do_apply/3

Restarting the Phoenix server (without changing any files) fixed the problem (for now) and all seems to be working again.

My Elixir version is 1.11.2

Any idea what might be going on?

Thanks!

aaronrenner commented 4 years ago

If your server was running while you ran the generator, that is to be expected. phx.gen.auth injects some dependencies in your project's mix.exs file, which requires the phoenix server to be restarted before a page can be loaded again.

dbi1 commented 4 years ago

Hmm, oddly I wasn't doing anything. I ran the generator before I started the server, but pretty sure not while it was running...

dbi1 commented 4 years ago

The last thing it shows in the Phoenix server log before showing the above error was a successful query:

[info] GET /users/settings
[debug] Processing with MyAppWeb.UserSettingsController.edit/2
  Parameters: %{}
  Pipelines: [:browser, :require_authenticated_user]
[debug] QUERY OK source="users_tokens" db=1.0ms idle=806.2ms
SELECT u1."id", u1."email", u1."hashed_password", u1."confirmed_at", u1."inserted_at", u1."updated_at" FROM "users_tokens" AS u0 INNER JOIN "users" AS u1 ON u1."id" = u0."user_id" WHERE ((u0."token" = $1) AND (u0."context" = $2)) AND (u0."inserted_at" > $3::timestamp + (-60::decimal::numeric * interval '1 day')) [<<list of numbers redacted out>>, "session", ~U[2020-11-12 14:28:50.903010Z]]
[info] Sent 200 in 2ms
josevalim commented 4 years ago

The error is correct. You have to restart the server if you or anything touched the mix.exs file.

dbi1 commented 4 years ago

Got it, thank you!