I can't seem to get a very basic `update()` call t...
# help
f
I can't seem to get a very basic
update()
call to work; I make this call:
Copy code
js
const { profileData, error } = supabase
      .from('profiles')
      .update({ 'username': emailUsername(user.email) })
      .eq('id', user.id)
And I get a 404 response:
Copy code
json
{
  error: [],
  data: null,
  count: null,
  status: 404,
  statusText: 'Not Found',
  body: null
}
Even though
user.id
in my request exactly matches an id in a row in my profiles table.
n
Hello @fugu! This thread has been automatically created from your message in #843999948717555735 a ``few seconds ago``. Pinging @User so that they see this as well! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ... menu) and select Leave Thread to unsubscribe from future updates. Want to change the title? Use the
/title
command! We have solved your problem? Click the button below to archive it.
f
When I make the call
supabase.from('profiles').select('id')
I get this:
Copy code
json
{
  error: null,
  data: [
    { id: '594f5d1d-eb4a-4508-8638-65d0437219c9' },
    { id: '45163b0c-eca5-4fb2-a71f-999a8342fad0' }
  ],
  count: null,
  status: 200,
  statusText: 'OK',
  body: [
    { id: '594f5d1d-eb4a-4508-8638-65d0437219c9' },
    { id: '45163b0c-eca5-4fb2-a71f-999a8342fad0' }
  ]
}
Which are the two entries in my profiles table, including one with an id that exactly matches.
ok, when I disable RLS, the update call works, so the problem is with my RLS somehow. However I have a policy set to allow what I'm doing, copied straight from the RLS documentation:
n
🆕 RLS 404 when updating table despite copying policy from documention
RLS 404 when updating table despite copying policy from documention
g
Is this code running with basic supabase.js on client only, or is this request coming from server side code? Even though you have a user object, you need a valid access token for the user when you use auth.uid(). You can try RLS on, and a policy auth.role() = 'anon' and see if that works. If it does you do not have a user token setup, just the default anon token.
f
That was the solution, I was trying to run it from a file in my /api path (aka the server side). TY
Still a bit awkward to try to only run the code when the user signs in for the first time, but I was able to figure it out
n
Thread was archived by @fugu. Anyone can send a message to unarchive it.