benonymus
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
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 10- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
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.
benonymus
ok found something, I changed it into this:
|> Guardian.Plug.sign_in(user)but no I am having a new error:
(Guardian.Plug.UnauthenticatedError) {:error, :secret_not_found}stephane
Did you config guardian ? (
config.exs)benonymus
missed to change this part, thanks
7stud
I’ve got the same error (so frustrating!):
The stack trace seems to point to my SessionController:
Here’s my SessionController:
I checked the Guardian.Plug docs for the
sign_in()function:And, I"m calling sign_in() with the correct types for the arguments. I’m stuck.
Here’s my
config.exs:I’m using a UserManager context for the public interface:
Here’s my directory structure:
idi527
Your app actually fails at this line: guardian/lib/guardian.ex at 9ed23acbef1ddfde5a79c139570fada9399b0877 · ueberauth/guardian · GitHub
Looks like you are passing your user as
claims.7stud
How do you know that?
As far as I can tell, I’m passing the default for
claims, which is%{}:put_flash()returns aconn, so I am calling:Guardian.Plug.sign_in(conn, Guardian, user)and based on the definition of sign_in():
sign_in(conn, impl, resource, claims \\ %{}, opts \\ [])I’m actually calling:
Guardian.Plug.sign_in(conn, Guardian, user, %{}, [])idi527
See the stacktrace:
Try passing all arguments to
sign_inwithout relying on the defaults, something strange is going on:7stud
I tried this:
And, I got this warning:
In iex:
That looks like 5 arguments to me! So, I decided to pick the two most important arguments, and go with that:
new_conn = Guardian.Plug.sign_in(conn, user)That got rid of the Enumerable error. Now, I’ve got a routing error that I’m working on.
idi527
Dog.UserManager.Guardian.Plug != Guardian.PlugSeems like you’ve confused one with the other because of