trenpixster / addict

User management lib for Phoenix Framework
MIT License
645 stars 99 forks source link

Addict's /register tries to use MyApp.MyUser.__struct__? #53

Closed mrluc closed 9 years ago

mrluc commented 9 years ago

The app is appropriately configured:

iex>iex(5)> Mix.Config.read! "config/config.exs"
...
addict: [not_logged_in_url: "/error", db: Flashbang.Repo, user: Flashbang.User,
...

And this config appears to be getting to Addict.Repository:

iex(1)> Application.get_env :addict, :user
Flashbang.User

However, when following instructions to POST to the /register route, I get the following:

[info] POST /register
[debug] Processing by Addict.Controller.register/2
  Parameters: %{"_csrf_token" => "ZmAVDy0sA3VfBV0bKyJRFCNtBCllEAAAV4wxIkt7lveayKcNQU7N6w==", "email" => "h@h.com", "format" => "html", "password" => "[FILTERED]", "username" => "h"}
  Pipelines: [:browser]
[info] Sent 500 in 197ms
[error] #PID<0.311.0> running Flashbang.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /register
** (exit) an exception was raised:
    ** (UndefinedFunctionError) undefined function: MyApp.MyUser.__struct__/0 (module MyApp.MyUser is not available)
        MyApp.MyUser.__struct__()
        (elixir) lib/kernel.ex:1503: Kernel.struct/2
        lib/addict/repository.ex:22: Addict.Repository.create/1
        lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.create/4
        lib/addict/controller.ex:95: Addict.Controller.register/2
        lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
        (flashbang) lib/phoenix/router.ex:265: Flashbang.Router.dispatch/2
        (flashbang) web/router.ex:1: Flashbang.Router.do_call/2

Any ideas where the MyApp.MyUser reference is coming from? I git-grepped for it and it's not in my project, and as shown above addict's configuration seems to be correct...

trenpixster commented 9 years ago

@mrluc interesting; is it possible that you kept a reference to MyApp.MyUser somewhere else in the project? Did you try to search in all files for it? Addict itself doesn't reference MyApp.MyUser - apart from the example on README.md.

mrluc commented 9 years ago

Yeah, I git-grepped for it, and also as I mentioned above the env vals for addict are correct in a running iex, I can spit out the config and see its correct, spit out addicts get_env and see that's correct - but then a post result in that error! Crazy.

I know addict doesn't have that symbol in its project - I just wonder where that val could be coming from! My mix.exs had that value at one point, but no more, and I triggered re compilation of at least my code -- is there any way that the value could have been compiled into an addict artifact?

mrluc commented 9 years ago

... aaaand it looks like that was it. :) Completely deleting _build/ fixed it.

Feels like changing the config file should be enough, but it's working now; closing until/if I later find time to reproduce and document better.

trenpixster commented 9 years ago

Hah nice! I gotta change the configurations out of mix to avoid this kind of mess up :+1: