hassox / phoenix_guardian

A demo application showing usage of guardian and ueberauth
MIT License
299 stars 70 forks source link

Empty login/register form submission throws an error #39

Closed charleshan closed 8 years ago

charleshan commented 8 years ago
[error] #PID<0.524.0> running PhoenixGuardian.Endpoint terminated
Server: localhost:4000 (http)
Request: POST /auth/identity/callback
** (exit) an exception was raised:
    ** (ArgumentError) nil given for :uid. Comparison with nil is forbidden as it is unsafe. Instead write a query with is_nil/1, for example: is_nil(s.uid)
        (ecto) lib/ecto/query/builder/filter.ex:107: Ecto.Query.Builder.Filter.runtime!/6
        (ecto) lib/ecto/query/builder/filter.ex:98: Ecto.Query.Builder.Filter.runtime!/2
        (ecto) lib/ecto/repo/queryable.ex:304: Ecto.Repo.Queryable.query_for_get_by/3
        (ecto) lib/ecto/repo/queryable.ex:52: Ecto.Repo.Queryable.get_by/5
        (phoenix_guardian) web/auth/user_from_auth.ex:117: PhoenixGuardian.UserFromAuth.auth_and_validate/2
        (phoenix_guardian) web/auth/user_from_auth.ex:7: PhoenixGuardian.UserFromAuth.get_or_insert/3
        (phoenix_guardian) web/controllers/auth_controller.ex:24: PhoenixGuardian.AuthController.callback/4
        (phoenix_guardian) web/controllers/auth_controller.ex:1: PhoenixGuardian.AuthController.action/2
        (phoenix_guardian) web/controllers/auth_controller.ex:1: PhoenixGuardian.AuthController.phoenix_controller_pipeline/2
        (phoenix_guardian) lib/phoenix/router.ex:261: PhoenixGuardian.Router.dispatch/2
        (phoenix_guardian) web/router.ex:1: PhoenixGuardian.Router.do_call/2
        (phoenix_guardian) lib/phoenix_guardian/endpoint.ex:1: PhoenixGuardian.Endpoint.phoenix_pipeline/1
        (phoenix_guardian) lib/plug/debugger.ex:122: PhoenixGuardian.Endpoint."call (overridable 3)"/2
        (phoenix_guardian) lib/phoenix/endpoint/render_errors.ex:34: PhoenixGuardian.Endpoint.call/2
        (plug) lib/plug/adapters/cowboy/handler.ex:15: Plug.Adapters.Cowboy.Handler.upgrade/4
        (cowboy) src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
walter commented 8 years ago

This happens for the identity provider for either login or sign up when the form is submitted without any values filled out in their respective forms.

I happen to be looking into this right now. Will let you know what I find.

charleshan commented 8 years ago

Here's a fix.

# web/auth/user_from_auth.ex
defp uid_from_auth(auth), do: auth.uid || "" 
walter commented 8 years ago

Works for me. Thanks for that @omin.

charleshan commented 8 years ago

@walter Thanks for working on the problem with me 👍

charleshan commented 8 years ago

Pull request #40