Carbon
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
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Hi everyone,
I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding.
I sta...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
So my question is quite simple and i have found no conclusive answer on forum, google or AI.
Should we use :erlang.float for Integer to ...
New
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
Other Trending Topics
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
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
- #metaprogramming
- #hex
- #security










Showing Posts 3 to 1- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
gregvaughn
The last argument to
rendershould 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.Carbon
hello,
this is the function thatis call on my POST request.
in this function icall the sign_in function thatiposted on my initial post.
this is my user schema
fuelen
Hello!
The code you’ve provided doesn’t emit this error. Could you show how do you render results?