sawthinkar

sawthinkar

Error: Getting this error message when the user tries to log in using OAuth2.

[debug] Processing with MyAppWeb.UserController.update/2
  Parameters: %{"id" => "undefined", "user" => %{"bio" => "bio", "email" => "email@gmail.com", "github_token" => "XXX", "github_uid" => "XXX", "image_url" => "https://avatars3.githubusercontent.com", "name" => "Name", "password" => "[FILTERED]", "username" => "username"}}
  Pipelines: [:api]
[info] Sent 400 in 14ms
[debug] ** (Ecto.Query.CastError) deps/ecto/lib/ecto/repo/queryable.ex:348: value `"undefined"` in `where` cannot be cast to type :id in query:

from u in MyApp.Accounts.User,
  where: u.id == ^"undefined",
  select: u

This is the UserController.ex

def update(conn, %{"id" => id, "user" => user_params}) do
  user = Accounts.get_user!(id)

  with {:ok, %User{} = user} <- Accounts.update_user(user, user_params) do
    render(conn, "show.json", user: user)
  end
end

The issue, so far I can think of, is when the user logs in using third party app, the account is not created in the database first, instead it is directed to the update profile page in the front-end which is in React. Then when the user submits the update profile form, id is undefined and is not able to get_user!(id).

  • Do I modify update() ? Adding case statement?

    undefined -> create()
    id -> update()
    

    But in this case, "undefined" seems different from nil, but I don’t know how.

  • Do I modify get_user()? Without !.

  • Do I create check_user_id()?

  • Do I change the flow of the OAuth2 Authentication; create the user before redirecting to update profile page?

  • Do I make changes from front-end before passing the parameters?

  • What are some decent standard options?

Ref: how to check if user id exists

Showing Posts 1 to 3

sneako

sneako

Since the id param is coming in as ‘undefined’, I would have to guess that your issue is in your JavaScript somewhere

jeremyjh

jeremyjh

update should only be called once the user record exists. The front-end should call a create route when id is undefined.

rickmutua

rickmutua

thanks for the heads-up. came across the same issue and fixed it

— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
jaybe78
Hello, I’m developing a online persistent chat system (what’s app) like using elixir/dynamodb/aws for a mobile app(flutter). The diffic...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
widianto
I think I’ve found a small improvement I could contribute to &lt;%= web_namespace %&gt;.CoreComponents (installer/templates/phx_web/compo...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews