Error: "permission denied for schema public" when trying to use a trigger function on a table created by Prisma #7094
-
Error: "permission denied for schema public" when trying to use a trigger function on a table created by Prisma Hi! I'm trying to use Prisma with Supabase Auth. I have defined my own public
Now I want to create a trigger function that runs every time the user signs up with Supabase auth. It looks like this:
And I set up a trigger to run it every time a user is INSERTed into Now when I try to sign up with Supabase Auth, I get an error "Database error saving new user", and when I look at Postgres logs, it says "permission denied for table profile". It worked perfectly fine when I created tables manually via Supabase UI, it stopped working when I tried to create tables with Prisma. What have I done wrong? How can I fix this? Full log:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
I don't know much about Prisma, but when Supabase dashboard creates a table it does it as user supabase_admin. Prisma is user postgres.
So my guess is your table is missing a grant that anon/authenticated/service_role need to access your table. |
Beta Was this translation helpful? Give feedback.
-
Recreated the whole project, remigrated the database, resetup the function and the trigger, and double checked that the function is created as a security definer. Now it works. |
Beta Was this translation helpful? Give feedback.
-
I had the same issue and I found out that the issue was given by creating the database with the postgres user. Ideally, you want to give If you try running If this is the case (as it was in my instance), the solution is to access the
|
Beta Was this translation helpful? Give feedback.
-
Had a similar bug, I was able to fix it with this
from here |
Beta Was this translation helpful? Give feedback.
Recreated the whole project, remigrated the database, resetup the function and the trigger, and double checked that the function is created as a security definer. Now it works.