mythicalprogrammer
Ueberauth failed to assign %{ueberauth_auth: auth} structure for some reason
Hi guys, my code is failing the pattern match and I have no idea why? I think ueberauth is doing something funky. Following this tutorial.
[debug] Processing with AppWeb.AuthenticationController.identity_callback/2 [54/1956]
Parameters: %{"user" => %{"email" => "reader@example.com", "password" => "[FILTERED]"}}
Pipelines: [:api]
[info] Sent 400 in 62ms
[debug] ** (Phoenix.ActionClauseError) no function clause matching in AppWeb.AuthenticationController.identity_callback/2
Controller code:
>> 7 def identity_callback(%{assigns: %{ueberauth_auth: auth}} = conn, _params) do
>> 8 IO.inspect("does this work?")
>> 9 #email = auth.uid
>> 10 #password = auth.credentials.other.password
>> 11 #handle_user_conn(Accounts.get_user_by_email_and_password(email, password), conn)
>> 12 end
I use curl:
curl \
-XPOST \
-v \
localhost:4000/api/auth/identity/callback \
-H 'content-type: application/json' \
-d '{"user": {"email": "reader@example.com", "password": "qweqweqwe"}}'
Thanks in advance
I’ve tested this function in iex -S mix and it works so I believe ueberauth is failing to assign the structure to my conn for some reason.
Marked As Solved
mythicalprogrammer
Thank you.
Got this message:
Request: POST /api/auth/identity/callback [32/1957]
** (exit) an exception was raised:
** (RuntimeError) expected action/2 to return a Plug.Conn, all plugs must receive a connection (conn) and return a connection, got: %{"user" => %{"email" => "reader@example.com", "password" => "qweqweqwe"}}
It’s something to work on.
update:
I got it thank you so much.
My config file was missing the base_path:
35 config :ueberauth, Ueberauth,
36 base_path: "/api/auth",
Thank you again!
Also Liked
NobbZ
Have you checked using a catch-all clause what is actually comming into your function? Thats usually the first thing to do when debugging match-errors:
def identity_callback(conn, params) do
IO.inspect(conn, label: :conn)
IO.inspect(params, label: :params)
end
aarkhipov
Yeah, I came to the same conclusion - I checked out today, and if I change routes to be prefixed with /auth, everything works without defining base_path. My problem was that I didn’t notice that routes in the example repo are prefixed with /auth via scope and for my app I took only what was inside of the scope, without /auth.
Popular in Questions
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance









