pow-auth / pow_assent

Multi-provider authentication for your Pow enabled app
https://powauth.com
MIT License
321 stars 50 forks source link

Warning from dialyzer : Invalid type specification for function #163

Closed jagoanmamah closed 4 years ago

jagoanmamah commented 4 years ago

Screenshot from 2020-04-13 05-19-49

Invalid type specification for function 'Elixir.MyAppWeb.Pow.Messages.PowAssent.Phoenix.Messages ':user_has_been_created/1. The success typing is 
          (#{'__struct__' := 'Elixir.Plug.Conn',
            'adapter' := {atom(), _},
            'assigns' := #{atom() => _},
            'before_send' := [fun((map()) -> map())],
            'body_params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'cookies' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'halted' := _,
            'host' := binary(),
            'method' := binary(),
            'owner' := pid(),
            'params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'path_info' := [binary()],
            'path_params' :=
                #{binary() =>
                      binary() |
                      [binary() | [any()] | map()] |
                      #{binary() => binary() | [any()] | map()}},
            'port' := char(),
            'private' := #{atom() => _},
            'query_params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() =>
                      binary() |
                      [binary() | [any()] | map()] |
                      #{binary() => binary() | [any()] | map()}},
            'query_string' := binary(),
            'remote_ip' :=
                {byte(), byte(), byte(), byte()} |
                {char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char()},
            'req_cookies' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => binary()},
            'req_headers' := [{binary(), binary()}],
            'request_path' := binary(),
            'resp_body' :=
                'nil' |
                binary() |
                maybe_improper_list(binary() |
                                    maybe_improper_list(any(),
                                                        binary() | []) |
                                    byte(),
                                    binary() | []),
            'resp_cookies' := #{binary() => #{}},
            'resp_headers' := [{binary(), binary()}],
            'scheme' := 'http' | 'https',
            'script_name' := [binary()],
            'secret_key_base' := 'nil' | binary(),
            'state' :=
                'chunked' | 'file' | 'sent' | 'set' | 'set_chunked' |
                'set_file' | 'unset',
            'status' := 'nil' | non_neg_integer()}) ->
             'nil'
Invalid type specification for function 'Elixir.MyAppWeb.Pow.Messages.PowAssent.Phoenix.Messages':signed_in/1. The success typing is 
          (#{'__struct__' := 'Elixir.Plug.Conn',
            'adapter' := {atom(), _},
            'assigns' := #{atom() => _},
            'before_send' := [fun((map()) -> map())],
            'body_params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'cookies' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'halted' := _,
            'host' := binary(),
            'method' := binary(),
            'owner' := pid(),
            'params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => _},
            'path_info' := [binary()],
            'path_params' :=
                #{binary() =>
                      binary() |
                      [binary() | [any()] | map()] |
                      #{binary() => binary() | [any()] | map()}},
            'port' := char(),
            'private' := #{atom() => _},
            'query_params' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() =>
                      binary() |
                      [binary() | [any()] | map()] |
                      #{binary() => binary() | [any()] | map()}},
            'query_string' := binary(),
            'remote_ip' :=
                {byte(), byte(), byte(), byte()} |
                {char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char(),
                 char()},
            'req_cookies' :=
                #{'__struct__' => 'Elixir.Plug.Conn.Unfetched',
                  'aspect' => atom(),
                  binary() => binary()},
            'req_headers' := [{binary(), binary()}],
            'request_path' := binary(),
            'resp_body' :=
                'nil' |
                binary() |
                maybe_improper_list(binary() |
                                    maybe_improper_list(any(),
                                                        binary() | []) |
                                    byte(),
                                    binary() | []),
            'resp_cookies' := #{binary() => #{}},
            'resp_headers' := [{binary(), binary()}],
            'scheme' := 'http' | 'https',
            'script_name' := [binary()],
            'secret_key_base' := 'nil' | binary(),
            'state' :=
                'chunked' | 'file' | 'sent' | 'set' | 'set_chunked' |
                'set_file' | 'unset',
            'status' := 'nil' | non_neg_integer()}) ->
             'nil'
danschultzer commented 4 years ago

Can you post the user_has_been_created and signed_in methods you have added?

jagoanmamah commented 4 years ago
defmodule MyAppWeb.Pow.Messages do
  use Pow.Phoenix.Messages
  use Pow.Extension.Phoenix.Messages,
    extensions: [PowAssent,PowResetPassword, PowEmailConfirmation]

  import MyAppWeb.Gettext

  def user_not_authenticated(_conn), do: gettext("Anda harus masuk untuk melihat halaman ini.")

  # Message methods for extensions has to be prepended with the snake cased
  # extension name. So the `email_has_been_sent/1` method from
  # `PowResetPassword` is written as `pow_reset_password_email_has_been_sent/1`
  # in your messages module.
  def pow_reset_password_email_has_been_sent(_conn), do: gettext("Email dengan instruksi atur ulang kata sandi telah dikirimkan kepada Anda. Silakan periksa kotak masuk Anda.")

  def invalid_credentials(_conn), do: gettext("Detail masuk yang disediakan tidak berfungsi. Harap verifikasi identitas Anda, dan coba lagi.")

  def user_has_been_created(_conn), do: gettext("Pengguna sudah dibuat.")

  def pow_email_confirmation_email_confirmation_required(_conn), do: gettext("Anda harus mengkonfirmasi email Anda sebelum dapat masuk. Tautan konfirmasi email telah dikirimkan kepada Anda.")

  def pow_email_confirmation_email_has_been_confirmed(_conn), do: gettext("Alamat email telah dikonfirmasi.")

  def pow_reset_password_password_has_been_reset(_conn), do: gettext("Kata sandi telah diperbarui.")

  def pow_reset_password_maybe_email_has_been_sent(_conn), do: gettext("Email dengan instruksi atur ulang kata sandi telah dikirimkan kepada Anda. Silakan periksa kotak masuk Anda.")

  # def pow_assent_signed_in(conn) do
  #   provider = Phoenix.Naming.humanize(conn.params["provider"])

  #   gettext("Anda sudah masuk dengan %{provider}.", provider)

  # end

end
danschultzer commented 4 years ago

If you pull from master branch with {:pow_assent, github: "pow-auth/pow_assent"}, this should have been resolved.

rompetomp commented 4 years ago

Hi

I got Dialyzer errors when not overwriting the user_has_been_created/1 and signed_in/1 messages:

Invalid type specification for function 'Elixir.TaskmanWeb.Pow.Messages.PowAssent.Phoenix.Messages':user_has_been_created/1. The success typing is 
          (_) -> 'nil'
Invalid type specification for function 'Elixir.TaskmanWeb.Pow.Messages.PowAssent.Phoenix.Messages':signed_in/1. The success typing is 
          (_) -> 'nil'

This is my messages file:

defmodule MyAppWeb.Pow.Messages do
  use Pow.Phoenix.Messages
  use Pow.Extension.Phoenix.Messages,
    extensions: [PowEmailConfirmation, PowPersistentSession, PowResetPassword, PowAssent]

  def pow_assent_could_not_sign_in(_conn),
    do: "Couldn't sign you in."
end

I'm new at elixir and phoenix, so apologies if I'm doing something wrong.

danschultzer commented 4 years ago

Sorry for late reply @rompetomp. I found the issue in Pow, and fixed it with https://github.com/danschultzer/pow/pull/520

If you use the master branch with {:pow, github: "danschultzer/pow", override: true} it should no longer output the warnings. Let me know if that resolves it!