point-source / supabase-tenant-rbac

A template for implementing basic RBAC for a multi-tenant supabase project
BSD 2-Clause "Simplified" License
300 stars 25 forks source link

Error db_pre_request not exist #29

Open bangdragon opened 1 month ago

bangdragon commented 1 month ago

I create the extension in my schema called rbac. Then it show error: no moddatetime extension found, then I install moddatetime in schema rbac. And install the supabase_rbac extension successfully. Then I login in my app and get this error in log at supabase dashboard at postgres log tab:

Event message
function db_pre_request() does not exist
Severity
ERROR

Timestamp
2024-07-31T17:56:51.803Z

Postgres Username
authenticator

Session ID
Xxxx.xxxxxx

No function matches the given name and argument types. You might need to add explicit type casts.

But I can see the db_pre_request function name in tab function at schema rbac

Also, at supabase dashboard in tab auth, it show error log:

{"component":"api","error":"500: Database error saving new user","level":"info","method":"POST","msg":"server_error: Internal Server Error","path":"/token","referer":"https://www.mywebsite.com","remote_addr":"xxx.xx5.xx.109","request_id":"xxxccccc704c6-HKG","time":"2024-07-31T17:31:25Z"}
point-source commented 1 month ago

Oh this is interesting. I think this may be caused by this line:

-- Enable the db_pre_request hook for the authenticator role
ALTER ROLE authenticator
SET
  pgrst.db_pre_request TO 'db_pre_request';

Specifically that the function name does not include the schema. I will have to do some tests and see if that's what it is. If so, this is a bug in need of fixing. Thanks for the report!

bangdragon commented 6 days ago

When you fix it