I have Phoenix app which uses oauth2 protocol to provide protected api. In order to do that I use Shield library: https://github.com/mustafaturan/shield.
Problem that occurs in my case is related with compilation order. In Shield library on compile time I can provide my own model to be used as main resource. Since shield library is compiled before my project, it doesn’t know anything about existance of this model. I’m getting:
** (CompileError) lib/shield/policies/user/register.ex:21: MyApp.User.__struct__/1 is undefined, cannot expand struct MyApp.User
I tried this configuration:
def project do
[app: :my_app,
version: "0.0.1",
elixir: "~> 1.4.1",
elixirc_paths: elixirc_paths(Mix.env),
compilers: [:phoenix, :gettext] ++ Mix.compilers,
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
aliases: aliases(),
deps: deps()]
end
def application do
[mod: {MyApp, []},
extra_applications: [:logger, :my_app, :shield]]
end
defp deps do
[{:phoenix, "~> 1.2.4"},
{:phoenix_pubsub, "~> 1.0"},
{:phoenix_ecto, "~> 3.0"},
{:postgrex, ">= 0.0.0"},
{:phoenix_html, "~> 2.6"},
{:phoenix_live_reload, "~> 1.0", only: :dev},
{:gettext, "~> 0.11"},
{:cowboy, "~> 1.0"},
{:ex_machina, "~> 2.0"},
{:shield, "~> 0.7.0"},
{:timex, "~> 3.1.24"}]
end
And it didn’t help. How to make sure that my app models are compiled and visible for external libraries on compile time ?