Hello, I've gone through this entire channel tryin...
# sql
d
Hello, I've gone through this entire channel trying to figure out why my update trigger isn't working, but none of the solutions seemed to help. I'm trying to sync my username from the auth.user's metadata with the public.profiles username column Here is the function I use for my trigger:
Copy code
begin
  if (old.raw_user_meta_data != new.raw_user_meta_data) then
    update public.profiles
    set username = new.raw_user_meta_data ->> 'username'
    where id = new.id;
  end if;
  return new;
end;
And here is my simple auth.update function:
**const** { user, error } = await auth.update({ data: { username: username } });
For some reason, this results in an error. I know it has to be something with the trigger/function, because the update is successful without it. Any ideas?
g
It is late for me, but I don't see anything wrong in your code. You might look in the postgres log in database to see if there is an error. Could be RLS (if function not security definer and you don't allow updates?), a mismatched col type, or I missed something in your code...
d
I didn't have RLS enabled on the auth table initially, but after adding it & the security definer, things started working.
Thank you for the help 🙏🏾 @garyaustin