trenpixster / addict

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

Addict routes/controllers not working on Phoenix 0.15, Addict 0.0.5 #49

Closed jjt closed 9 years ago

jjt commented 9 years ago

Generated app through mix phoenix.new, followed Addict setup instructions.

POSTing to /register:

Request: POST /register
** (exit) an exception was raised:
    ** (UndefinedFunctionError) undefined function: nil.__struct__/0
        nil.__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
        (bacro) lib/phoenix/router.ex:265: Bacro.Router.dispatch/2
        (bacro) web/router.ex:1: Bacro.Router.do_call/2

POSTing to /login:

Request: POST /login
** (exit) an exception was raised:
    ** (UndefinedFunctionError) undefined function: nil.__schema__/1
        nil.__schema__(:source)
        lib/addict/repository.ex:74: Addict.Repository.find_by_email/1
        lib/addict/interactors/addict_manager_interactor.ex:161: Addict.ManagerInteractor.verify_password/4
        lib/addict/controller.ex:95: Addict.Controller.login/2
        lib/addict/controller.ex:89: Addict.Controller.phoenix_controller_pipeline/2
        (bacro) lib/phoenix/router.ex:265: Bacro.Router.dispatch/2
        (bacro) web/router.ex:1: Bacro.Router.do_call/2
        (bacro) lib/bacro/endpoint.ex:1: Bacro.Endpoint.phoenix_pipeline/1

config.exs

config :addict, not_logged_in_url: "/error",
                db: Bacro.Repo,
                user: Bacro.User,
                register_from_email: "Registration <welcome@yourawesomeapp.com>",
                register_subject: "Welcome to yourawesomeapp!",
                password_recover_from_email: "Password Recovery <no-reply@yourawesomeapp.com>",
                password_recover_subject: "You requested a password recovery link",
                email_templates: Bacro.Presenters.EmailPresenter

router.ex

defmodule Bacro.Router do
  use Bacro.Web, :router
  use Addict.RoutesHelper

  pipeline :browser do
    plug :accepts, ["html"]
    plug :fetch_session
    plug :fetch_flash
    plug :protect_from_forgery
  end

  pipeline :api do
    plug :accepts, ["json"]
  end

  scope "/", Bacro do
    pipe_through :browser # Use the default browser stack

    get "/", PageController, :index
    get "/auth/register", AuthController, :register
  end

  scope "/" do
    addict :routes
  end
end

$ mix phoenix.routes

            page_path  GET   /                  Bacro.PageController :index
            auth_path  GET   /auth/register     Bacro.AuthController :register
        register_path  POST  /register          Addict.Controller :register
           login_path  POST  /login             Addict.Controller :login
          logout_path  POST  /logout            Addict.Controller :logout
recover_password_path  POST  /recover_password  Addict.Controller :recover_password
  reset_password_path  POST  /reset_password    Addict.Controller :reset_password

mix.lock

%{"addict": {:hex, :addict, "0.0.5"},
  "comeonin": {:hex, :comeonin, "0.11.3"},
  "cowboy": {:hex, :cowboy, "1.0.2"},
  "cowlib": {:hex, :cowlib, "1.0.1"},
  "decimal": {:hex, :decimal, "1.1.0"},
  "ecto": {:hex, :ecto, "0.14.3"},
  "fs": {:hex, :fs, "0.9.2"},
  "mailgun": {:hex, :mailgun, "0.0.2"},
  "phoenix": {:hex, :phoenix, "0.15.0"},
  "phoenix_ecto": {:hex, :phoenix_ecto, "0.8.1"},
  "phoenix_html": {:hex, :phoenix_html, "1.4.0"},
  "phoenix_live_reload": {:hex, :phoenix_live_reload, "0.5.1"},
  "plug": {:hex, :plug, "0.14.0"},
  "poison": {:hex, :poison, "1.4.0"},
  "poolboy": {:hex, :poolboy, "1.5.1"},
  "postgrex": {:hex, :postgrex, "0.9.1"},
  "ranch": {:hex, :ranch, "1.1.0"}}

I'm new to Elixir and Phoenix, so let me know if there is anything else helpful that I can attach.

jjt commented 9 years ago

Weird... this isn't an issue any more after

rm -rf _build deps mix.lock && mix deps.clean --unused && mix deps.get

My mix.lock is identical to what I posted before ¯_(ツ)_/¯

trenpixster commented 9 years ago

@jjt I've sometimes bumped into that kind of issues too. It seems the deps folder gets incorrect with some runs on deps.get on new packages/versions and the only I'm able to solve that is by running mix deps.clean --alland installing it all over again. Anyway, glad you were able to work around it :+1: