Unexpected error in database trigger
Following the basic example of creating a profile when a new user is created in the
auth.users
table, it works fine when simply inserting a new record into the public.profiles
table as follows:
However, if I use the same invite_id
from raw_user_meta_data
to update the public.invites
table as follows, I get an error:
The error has a code of "unexpected_failure" and a message of "Database error saving new user". The schema is correct and the RLS policy allows updates to the public.invites
table, not sure what else it could be. Hard to debug these triggers.2 Replies
What is the Postgres log error?
You can also use
raise log 'new = %',new;
and check the postgres log to see what is in new. There are many updates on auth.users and not all contain all the data of the row.Haha, I didn't even realize how much logging there is in the Supabase dashboard now. When I go to the Logs -> Postgres tab there didn't seem to be much, but in the Logs -> Auth tab, there is a much more descriptive error:
Thanks for the tip about the logs! I should be able to sort it out now.
Solved! I was referencing the id of the newly created profile record as a foreign key for the updated invite record, BEFORE I had actually inserted the new record in the profile table. I just needed to switch the order of operations, this works:
Much easier to debug now that I know about the logs, thanks again!