benonymus
Protocol Enumerable not implemented for error with guardian login
Hey I a trying to make a login system for my phoenix app, but I am having an error on successful login attempt:
# protocol Enumerable not implemented for %Userteam1.Web.User{__meta__: #Ecto.Schema.Metadata<:loaded, "users">, id: 1, inserted_at: ~N[2018-08-19 09:10:38.661295], name: "bence", password: nil, password_hash: "$2b$12$EEH/mgGuM1GyKHkUSIJG..THKJ6W/0iN/tWH6FiikZ4dRjGqPwt3G", role: #Ecto.Association.NotLoaded<association :role is not loaded>, role_id: 1, team: #Ecto.Association.NotLoaded<association :team is not loaded>, team_id: nil, updated_at: ~N[2018-08-19 09:10:38.661303]}. This protocol is implemented for: DBConnection.PrepareStream, DBConnection.Stream, Date.Range, Ecto.Adapters.SQL.Stream, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Postgrex.Stream, Range, Stream
my controller for login looks like this:
def create(conn, %{"session" => %{"name" => name, "password" => password}}) do
case Userteam1.Web.name_password_auth(name, password) do
{:ok, user} ->
IO.inspect(user)
conn
|> put_flash(:info, "Successfully signed in")
|> Guardian.encode_and_sign(user)
|> redirect(to: user_path(conn, :index))
{:error, _reason} ->
conn
|> put_flash(:error, "Invalid name or password")
|> render("new.html")
end
end
and my schema that it is trying to load looks like this:
schema "users" do
field(:name, :string)
field(:password_hash, :string)
field(:password, :string, virtual: true)
belongs_to(:role, Userteam1.Role)
belongs_to(:team, Userteam1.Team)
timestamps()
end
How can this be fixed?
Trending in Questions
Other Trending 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
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #performance
- #security










Marked As Solved
stephane
Did you config guardian ? (
config.exs)Also Liked
idi527
Dog.UserManager.Guardian.Plug != Guardian.PlugSeems like you’ve confused one with the other because of
7stud
First time trying Guardian–I did not know that!
And, I checked that line to make sure that
Guardian.Plugwas indeed equivalent toDog.UserManager.Guardian.Plug! All that code is from the official Guardian “Getting Started Tutorial”.And, the route problem I was having was due to the tutorial alternately using “/protected” and “/secret” to refer to the Guardian protected route.
By the way, things work when I do:
So, I guess I was looking at the wrong docs??? This is what my
lib/dog/user_manager/guardian.exfile looks like:I guess the line:
injects a Plug module? I looked at the source code for the Guardian module:
And Guardian.Plug’s
__using__()function looks like this:And, there’s the two argument
sign_in()function that I lucked into; and, like you said, the way I was calling it originally:matched the parameter variable
claimsto user.lol. And the original solution to this question was:
Thanks idiot!
NobbZ
Guardian.encode_and_sign/4does not return aPlug.Conn.t, nor anything that would implement theEnumerableprotocol.Please give the Getting Started of guardian another read and try to incorporate the things you learned there into your application.