bigbassroller
Ueberauth Guardian - [error] protocol Enumerable not implemented for %AuthMe.UserManager.User
Hi,
Just went through the getting started tutorial of Ueberauth Guardian, guardian/guides/tutorial/start-tutorial.md at master · ueberauth/guardian · GitHub and getting the following error:
[debug] Processing with AuthMeWeb.SessionController.login/2
Parameters: %{"_csrf_token" => "ED8hNV01HAoVJgUNJgFUCE01d0NPLhVfvMNv9rRLwB2Fyv-cxE8q6Zzo", "_utf8" => "✓", "user" => %{"password" => "[FILTERED]", "username" => "me"}}
Pipelines: [:browser, :auth]
[debug] QUERY OK source="users" db=0.4ms
SELECT u0."id", u0."email", u0."password", u0."username", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."username" = $1) ["me"]
[info] Sent 500 in 332ms
[error] #PID<0.494.0> running AuthMeWeb.Endpoint (connection #PID<0.486.0>, stream id 4) terminated
Server: localhost:4000 (http)
Request: POST /login
** (exit) an exception was raised:
** (Protocol.UndefinedError) protocol Enumerable not implemented for %AuthMe.UserManager.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, email: "me@me.com", id: 1, inserted_at: ~N[2019-07-27 10:02:07], password: "$argon2id$v=19$m=131072,t=8,p=4$/U8dnLAcxhvQWu3uNrQmGw$FBsHeET8o9+ecOrr2s7y+I3JRneZJUP1r5QJg66usKY", updated_at: ~N[2019-07-27 10:02:07], username: "me"}. This protocol is implemented for: Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.Stream, DBConnection.PrepareStream, HashSet, Range, Map, Function, List, Stream, Date.Range, HashDict, GenEvent.Stream, MapSet, File.Stream, IO.Stream
(elixir) /private/tmp/elixir-20190202-21222-1ilp2g0/elixir-1.8.1/lib/elixir/lib/enum.ex:1: Enumerable.impl_for!/1
(elixir) /private/tmp/elixir-20190202-21222-1ilp2g0/elixir-1.8.1/lib/elixir/lib/enum.ex:141: Enumerable.reduce/3
(elixir) lib/enum.ex:3015: Enum.reverse/1
(elixir) lib/enum.ex:2647: Enum.to_list/1
(elixir) lib/map.ex:181: Map.new_from_enum/1
(guardian) lib/guardian.ex:573: Guardian.encode_and_sign/4
(guardian) lib/guardian/plug.ex:208: Guardian.Plug.sign_in/5
(auth_me) lib/auth_me_web/controllers/session_controller.ex:30: AuthMeWeb.SessionController.login_reply/2
(auth_me) lib/auth_me_web/controllers/session_controller.ex:1: AuthMeWeb.SessionController.action/2
(auth_me) lib/auth_me_web/controllers/session_controller.ex:1: AuthMeWeb.SessionController.phoenix_controller_pipeline/2
(phoenix) lib/phoenix/router.ex:288: Phoenix.Router.__call__/2
(auth_me) lib/auth_me_web/endpoint.ex:1: AuthMeWeb.Endpoint.plug_builder_call/2
(auth_me) lib/plug/debugger.ex:122: AuthMeWeb.Endpoint."call (overridable 3)"/2
(auth_me) lib/auth_me_web/endpoint.ex:1: AuthMeWeb.Endpoint.call/2
(phoenix) lib/phoenix/endpoint/cowboy2_handler.ex:40: Phoenix.Endpoint.Cowboy2Handler.init/2
(cowboy) /Users/bigbassroller2017/Sites/space-rocket-phx/auth_me/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
(cowboy) /Users/bigbassroller2017/Sites/space-rocket-phx/auth_me/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
(cowboy) /Users/bigbassroller2017/Sites/space-rocket-phx/auth_me/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
(stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
lib/auth_me_web/controllers/session_controller.ex
defmodule AuthMeWeb.SessionController do
use AuthMeWeb, :controller
alias AuthMe.{UserManager, UserManager.User, UserManager.Guardian}
def new(conn, _) do
changeset = UserManager.change_user(%User{})
maybe_user = Guardian.Plug.current_resource(conn)
if maybe_user do
redirect(conn, to: "/secret")
else
render(conn, "new.html", changeset: changeset, action: Routes.session_path(conn, :login))
end
end
def login(conn, %{"user" => %{"username" => username, "password" => password}}) do
UserManager.authenticate_user(username, password)
|> login_reply(conn)
end
def logout(conn, _) do
conn
|> Guardian.Plug.sign_out(Guardian, _opts = [])
|> redirect(to: "/login")
end
defp login_reply({:ok, user}, conn) do
conn
|> put_flash(:info, "Welcome back!")
|> Guardian.Plug.sign_in(Guardian, user)
|> redirect(to: "/protected")
end
defp login_reply({:error, reason}, conn) do
conn
|> put_flash(:error, to_string(reason))
|> new(%{})
end
end
lib/auth_me/user_manager/guardian.ex
defmodule AuthMe.UserManager.Guardian do
use Guardian, otp_app: :auth_me
alias AuthMe.UserManager
def subject_for_token(user, _claims) do
{:ok, to_string(user.id)}
end
def resource_from_claims(%{"sub" => id}) do
case UserManager.get_user(id) do
nil -> {:error, :resource_not_found}
user -> {:ok, user}
end
end
end
I am not sure what the issue is. It sounds like the struct is in the wrong format.
I put the code up on a repo along with revised tutorial here: GitHub - space-rocket/auth-me: Phoenix authentication with Ueberauth and Guardian · GitHub
Any help very appreciated!
Most Liked
idi527
![]()
I think the error is the same as in Protocol Enumerable not implemented for error with guardian login - #11 by idi527
1
Popular in Questions
Hello everyone,
I try to use an Javascript Event Handler in my root.html.leex file.
Therefore I created a function in the app.js file: ...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I’m writing a test for one of the...
New
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
15:22:35.803 [error] gen_event {lager_file_backend...
New
The Elixir Typespec docs show the following syntax for keyword lists in typespecs:
# ...
| [key: type] # keyword lists...
New
I will often find my self writing things similar to:
case some_value do
nil -> something()
"" -> something()
_ -> somethi...
New
i’m a new one to elixir
which editor can i use
vs code? or atom?
Thanks! :smiley:
New
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar.
I p...
New
I am trying to run a deploy with docker and I successfully runned with this command:
docker build -t romenigld/blog-prod .
but when I t...
New
Lets say I have map like this fetching from my database
%{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
Other popular topics
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service.
Currently when I de...
New
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
Hi everyone,
One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
What learn first? Rust or Elixir
Hi Elixir community!
I’m here because i want learn a new language. I’m a junior developer and mainly i ...
New
I have VueJS GUIs with the project generated using Webpack.
I have Elixir modules that will need to be used by the VueJS GUIs.
I forese...
New
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
Hello everyone,
Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
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








