Carbon

Carbon

Protocol Enumerable not implemented for %{__meta__: #Ecto.Schema.Metadata<:loaded, "auth_tokens">

Hi,

I want to make a sign_in and sign_out for my apiusing elixir with phoenix.
When i sign_in it create a user token but when i want to register this token on my “auth_tokens” table in db, i have this error :

INSERT INTO "auth_tokens" ("revoked","token","user_id","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5) RETURNING "id" [false, "SFMyNTY.g2gDdAAAAApkAAhfX21ldGFfX3QAAAAGZAAKX19zdHJ1Y3RfX2QAG0VsaXhpci5FY3RvLlNjaGVtYS5NZXRhZGF0YWQAB2NvbnRleHRkAANuaWxkAAZwcmVmaXhkAANuaWxkAAZzY2hlbWFkAB5FbGl4aXIuVGltZW1hbmFnZXIuR290aGFtLlVzZXJkAAZzb3VyY2VtAAAABXVzZXJzZAAFc3RhdGVkAAZsb2FkZWRkAApfX3N0cnVjdF9fZAAeRWxpeGlyLlRpbWVtYW5hZ2VyLkdvdGhhbS5Vc2VyZAALYXV0aF90b2tlbnN0AAAABGQAD19fY2FyZGluYWxpdHlfX2QABG1hbnlkAAlfX2ZpZWxkX19kAAthdXRoX3Rva2Vuc2QACV9fb3duZXJfX2QAHkVsaXhpci5UaW1lbWFuYWdlci5Hb3RoYW0uVXNlcmQACl9fc3RydWN0X19kACFFbGl4aXIuRWN0by5Bc3NvY2lhdGlvbi5Ob3RMb2FkZWRkAAVlbWFpbG0AAAAMdGVzdEB0ZXN0LmZyZAACaWRhBWQAC2luc2VydGVkX2F0dAAAAAlkAApfX3N0cnVjdF9fZAAURWxpeGlyLk5haXZlRGF0ZVRpbWVkAAhjYWxlbmRhcmQAE0VsaXhpci5DYWxlbmRhci5JU09kAANkYXlhGmQABGhvdXJhCWQAC21pY3Jvc2Vjb25kaAJhAGEAZAAGbWludXRlYSZkAAVtb250aGEKZAAGc2Vjb25kYR1kAAR5ZWFyYgAAB-RkAAhwYXNzd29yZGQAA25pbGQADXBhc3N3b3JkX2hhc2htAAAAPCQyYiQxMiRTcE8zTjR6TkVLemZzVm1Ic0pJaHZ1WW5VMy5sUTYzbzVJR3JTanVNdDNCMEU3N05kYVdjU2QACnVwZGF0ZWRfYXR0AAAACWQACl9fc3RydWN0X19kABRFbGl4aXIuTmFpdmVEYXRlVGltZWQACGNhbGVuZGFyZAATRWxpeGlyLkNhbGVuZGFyLklTT2QAA2RheWEaZAAEaG91cmEJZAALbWljcm9zZWNvbmRoAmEAYQBkAAZtaW51dGVhJmQABW1vbnRoYQpkAAZzZWNvbmRhHWQABHllYXJiAAAH5GQACHVzZXJuYW1lbQAAAAR0ZXN0bgYAF3tvZHUBYgABUYA.OGNA_ZeoMe5R4x4dtbpuRXew5JANJOz1nSNuRNe9CyQ", 5, ~N[2020-10-26 10:23:49], ~N[2020-10-26 10:23:49]]
[info] Sent 500 in 422ms
[error] #PID<0.658.0> running TimemanagerWeb.Endpoint (connection #PID<0.657.0>, stream id 1) terminated
Server: localhost:4000 (http)
Request: POST /api/sessions/sign_in
** (exit) an exception was raised:
    ** (Protocol.UndefinedError) protocol Enumerable not implemented for %{__meta__: #Ecto.Schema.Metadata<:loaded, "auth_tokens">, __struct__: Timemanager.Gotham.AuthToken, conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :...}, assigns: %{__meta__: #Ecto.Schema.Metadata<:loaded, "auth_tokens">, __struct__: Timemanager.Gotham.AuthToken, id: 4, inserted_at: ~N[2020-10-26 10:23:49], layout: false, revoked: false, revoked_at: nil, token: "SFMyNTY.g2gDdAAAAApkAAhfX21ldGFfX3QAAAAGZAAKX19zdHJ1Y3RfX2QAG0VsaXhpci5FY3RvLlNjaGVtYS5NZXRhZGF0YWQAB2NvbnRleHRkAANuaWxkAAZwcmVmaXhkAANuaWxkAAZzY2hlbWFkAB5FbGl4aXIuVGltZW1hbmFnZXIuR290aGFtLlVzZXJkAAZzb3VyY2VtAAAABXVzZXJzZAAFc3RhdGVkAAZsb2FkZWRkAApfX3N0cnVjdF9fZAAeRWxpeGlyLlRpbWVtYW5hZ2VyLkdvdGhhbS5Vc2VyZAALYXV0aF90b2tlbnN0AAAABGQAD19fY2FyZGluYWxpdHlfX2QABG1hbnlkAAlfX2ZpZWxkX19kAAthdXRoX3Rva2Vuc2QACV9fb3duZXJfX2QAHkVsaXhpci5UaW1lbWFuYWdlci5Hb3RoYW0uVXNlcmQACl9fc3RydWN0X19kACFFbGl4aXIuRWN0by5Bc3NvY2lhdGlvbi5Ob3RMb2FkZWRkAAVlbWFpbG0AAAAMdGVzdEB0ZXN0LmZyZAACaWRhBWQAC2luc2VydGVkX2F0dAAAAAlkAApfX3N0cnVjdF9fZAAURWxpeGlyLk5haXZlRGF0ZVRpbWVkAAhjYWxlbmRhcmQAE0VsaXhpci5DYWxlbmRhci5JU09kAANkYXlhGmQABGhvdXJhCWQAC21pY3Jvc2Vjb25kaAJhAGEAZAAGbWludXRlYSZkAAVtb250aGEKZAAGc2Vjb25kYR1kAAR5ZWFyYgAAB-RkAAhwYXNzd29yZGQAA25pbGQADXBhc3N3b3JkX2hhc2htAAAAPCQyYiQxMiRTcE8zTjR6TkVLemZzVm1Ic0pJaHZ1WW5VMy5sUTYzbzVJR3JTanVNdDNCMEU3N05kYVdjU2QACnVwZGF0ZWRfYXR0AAAACWQACl9fc3RydWN0X19kABRFbGl4aXIuTmFpdmVEYXRlVGltZWQACGNhbGVuZGFyZAATRWxpeGlyLkNhbGVuZGFyLklTT2QAA2RheWEaZAAEaG91cmEJZAALbWljcm9zZWNvbmRoAmEAYQBkAAZtaW51dGVhJmQABW1vbnRoYQpkAAZzZWNvbmRhHWQABHllYXJiAAAH5GQACHVzZXJuYW1lbQAAAAR0ZXN0bgYAF3tvZHUBYgABUYA.OGNA_ZeoMe5R4x4dtbpuRXew5JANJOz1nSNuRNe9CyQ", updated_at: ~N[2020-10-26 10:23:49], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 5}, before_send: [#Function<0.79951527/1 in Plug.Telemetry.call/2>], body_params: %{"email" => "test@test.fr", "password" => "1234", "username" => "test"}, cookies: %{}, halted: false, host: "localhost", method: "POST", owner: #PID<0.658.0>, params: %{"email" => "test@test.fr", "password" => "1234", "username" => "test"}, path_info: ["api", "sessions", "sign_in"], path_params: %{}, port: 4000, private: %{TimemanagerWeb.Router => {[], %{PhoenixSwagger.Plug.SwaggerUI => []}}, :phoenix_action => :create, :phoenix_controller => TimemanagerWeb.SessionsController, :phoenix_endpoint => TimemanagerWeb.Endpoint, :phoenix_format => "json", :phoenix_layout => {TimemanagerWeb.LayoutView, :app}, :phoenix_request_logger => {"request_logger", "request_logger"}, :phoenix_router => TimemanagerWeb.Router, :phoenix_template => "show.json", :phoenix_view => TimemanagerWeb.SessionsView, :plug_session_fetch => #Function<1.108087556/1 in Plug.Session.fetch_session/1>}, query_params: %{}, query_string: "", remote_ip: {127, 0, 0, 1}, req_cookies: %{}, req_headers: [{"accept", "*/*"}, {"accept-encoding", "gzip, deflate, br"}, {"connection", "keep-alive"}, {"content-length", "76"}, {"content-type", "application/json"}, {"host", "localhost:4000"}, {"postman-token", "d6b3602a-6636-4338-a4f1-fe62bd4e15de"}, {"user-agent", "PostmanRuntime/7.26.5"}], request_path: "/api/sessions/sign_in", resp_body: nil, resp_cookies: %{}, resp_headers: [{"cache-control", "max-age=0, private, must-revalidate"}, {"x-request-id", "FkGDxfxm0cAsEh0AAAwD"}], scheme: :http, script_name: [], secret_key_base: :..., state: :unset, status: 200}, id: 4, inserted_at: ~N[2020-10-26 10:23:49], layout: false, revoked: false, revoked_at: nil, token: "SFMyNTY.g2gDdAAAAApkAAhfX21ldGFfX3QAAAAGZAAKX19zdHJ1Y3RfX2QAG0VsaXhpci5FY3RvLlNjaGVtYS5NZXRhZGF0YWQAB2NvbnRleHRkAANuaWxkAAZwcmVmaXhkAANuaWxkAAZzY2hlbWFkAB5FbGl4aXIuVGltZW1hbmFnZXIuR290aGFtLlVzZXJkAAZzb3VyY2VtAAAABXVzZXJzZAAFc3RhdGVkAAZsb2FkZWRkAApfX3N0cnVjdF9fZAAeRWxpeGlyLlRpbWVtYW5hZ2VyLkdvdGhhbS5Vc2VyZAALYXV0aF90b2tlbnN0AAAABGQAD19fY2FyZGluYWxpdHlfX2QABG1hbnlkAAlfX2ZpZWxkX19kAAthdXRoX3Rva2Vuc2QACV9fb3duZXJfX2QAHkVsaXhpci5UaW1lbWFuYWdlci5Hb3RoYW0uVXNlcmQACl9fc3RydWN0X19kACFFbGl4aXIuRWN0by5Bc3NvY2lhdGlvbi5Ob3RMb2FkZWRkAAVlbWFpbG0AAAAMdGVzdEB0ZXN0LmZyZAACaWRhBWQAC2luc2VydGVkX2F0dAAAAAlkAApfX3N0cnVjdF9fZAAURWxpeGlyLk5haXZlRGF0ZVRpbWVkAAhjYWxlbmRhcmQAE0VsaXhpci5DYWxlbmRhci5JU09kAANkYXlhGmQABGhvdXJhCWQAC21pY3Jvc2Vjb25kaAJhAGEAZAAGbWludXRlYSZkAAVtb250aGEKZAAGc2Vjb25kYR1kAAR5ZWFyYgAAB-RkAAhwYXNzd29yZGQAA25pbGQADXBhc3N3b3JkX2hhc2htAAAAPCQyYiQxMiRTcE8zTjR6TkVLemZzVm1Ic0pJaHZ1WW5VMy5sUTYzbzVJR3JTanVNdDNCMEU3N05kYVdjU2QACnVwZGF0ZWRfYXR0AAAACWQACl9fc3RydWN0X19kABRFbGl4aXIuTmFpdmVEYXRlVGltZWQACGNhbGVuZGFyZAATRWxpeGlyLkNhbGVuZGFyLklTT2QAA2RheWEaZAAEaG91cmEJZAALbWljcm9zZWNvbmRoAmEAYQBkAAZtaW51dGVhJmQABW1vbnRoYQpkAAZzZWNvbmRhHWQABHllYXJiAAAH5GQACHVzZXJuYW1lbQAAAAR0ZXN0bgYAF3tvZHUBYgABUYA.OGNA_ZeoMe5R4x4dtbpuRXew5JANJOz1nSNuRNe9CyQ", updated_at: ~N[2020-10-26 10:23:49], user: #Ecto.Association.NotLoaded<association :user is not loaded>, user_id: 5} of type Timemanager.Gotham.AuthToken (a struct). This protocol is implemented for the following type(s): Ecto.Adapters.SQL.Stream, Postgrex.Stream, DBConnection.PrepareStream, DBConnection.Stream, Date.Range, File.Stream, Function, GenEvent.Stream, HashDict, HashSet, IO.Stream, List, Map, MapSet, Range, Stream

this is my schema :

schema "auth_tokens" do
    belongs_to :user, User
    field :revoked, :boolean, default: false
    field :revoked_at, :utc_datetime
    field :token, :string
    timestamps()
  end

this is my sign_in function :

def sign_in(email, password) do
    case Comeonin.Bcrypt.check_pass(Repo.get_by(User, email: email), password) do
      {:ok, user} ->
        token = Authenticator.generate_token(user)
        Repo.insert(Ecto.build_assoc(user, :auth_tokens, %{token: token}))
      err -> err
    end
  end

if someone can help me please

Marked As Solved

gregvaughn

gregvaughn

The last argument to render should be a keyword list or a map. You’re just passing the auth_token, so Phoenix is trying to enumerate it to set up assigns and can’t.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
Kagamiiiii
Student &amp; New to elixir. Nice language. I want to convert a english character, e.g. “a”, which is stored in a variable, to it’s asci...
New
nsuchy
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
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
vonH
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
Nvim
Elixir appears to be a superior language to Python. I don’t see any advantage of Python over Elixir. Are there any?
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement