IS it possible for someone to meet with me over zo...
# sql
b
IS it possible for someone to meet with me over zoom to go over my project? I'm having trouble with row level security rules making it impossible for me to select data even though hte data is there. Not sure why I thikn the supabase client is logged in OK, my rule is very ysimple just uid()=user_id
g
Set your rule to auth.role() = 'anon'. If that works then you do not have a logged in user at the point you make your call. It takes some time for the supabase client to init even if you have a logged in user stored in local storage, longer if it has to refresh the jwt token. You can use this even handler to see if you signin event occurs before you make the call also. https://supabase.com/docs/reference/javascript/auth-onauthstatechange Also check that your user_id column is uuid type.
b
I am already using onAuthStateChange so that is good. hmmm. I noticed in the pollicy that auth.uid() gets shortened to uid() in hte ui. are they the same thing?
g
Yes, I don't like that the UI does that, but have had no issue.
I'm assuming you are getting back an empty array for data, not an error. If auth.role()='anon' works then your issue is client side. Otherwise show your select call and confirm user_id column is uuid.
b
Found the answer, apparently you can't call supabase from a next.js server api route as it will always have an unauthenticated request. Very strange but that is the conclusion I have come to, when I put my supabase code inside a react component so the request was made by the browser everything worked.
g
You have to pass the jwt to your server route and set up the client there and use setAuth(jwt) before making data requests. https://github.com/supabase-community/supabase-auth-helpers gives some idea of things going on the server to include even doing auth, which you may not need.