ueberauth / guardian

Elixir Authentication
MIT License
3.4k stars 381 forks source link

Compilation error in file guardian.ex: type options/0 undefined #686

Closed remi-martin closed 2 years ago

remi-martin commented 2 years ago

I have a classic guardian.ex file:

defmodule Guardian do
  use Guardian, otp_app: :todo_list

  def subject_for_token(user, _claims) do
    sub = to_string(user.id)
    {:ok, sub}
  end

  def subject_for_token(_, _) do
    {:error, :reason_for_error}
  end

  def resource_from_claims(claims) do
    id = claims["sub"]
    resource = MyApi.Accounts.get_user!(id)
    {:ok,  resource}
  end

  def resource_from_claims(_claims) do
    {:error, :reason_for_error}
  end
end

And when I try to start the server with phx mix.server, I get an error:

== Compilation error in file lib/todo_list/guardian.ex ==
** (CompileError) lib/todo_list/guardian.ex:2: type options/0 undefined (no such type in Guardian)
    (elixir 1.12.2) lib/kernel/typespec.ex:925: Kernel.Typespec.compile_error/2
    (stdlib 3.16) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.16) lists.erl:1359: :lists.mapfoldl/3
    (elixir 1.12.2) lib/kernel/typespec.ex:977: Kernel.Typespec.fn_args/5
    (elixir 1.12.2) lib/kernel/typespec.ex:963: Kernel.Typespec.fn_args/6
    (elixir 1.12.2) lib/kernel/typespec.ex:390: Kernel.Typespec.translate_spec/8
    (stdlib 3.16) lists.erl:1358: :lists.mapfoldl/3
    (stdlib 3.16) lists.erl:1359: :lists.mapfoldl/3

How can I fix this ?

remi-martin commented 2 years ago

defmodule Guardian do => defmodule MyApp.Guardian do