The code returns the following error:
fetch to https://svvguxhkhesrlzmydghw.supabase.co/rest/v1/request?select=id failed with status 401 and body: {"code":"42501","details":null,"hint":null,"message":"new row violates row-level security policy for table \"request\""}
at async submitTransportRequest (/app/actions/requests)
at async handleSubmit (/app/client-request/page)
Revise the code to address the error.
I was previewing: /client-request
Let me check the debug logs and investigate the restrictive policies that might be blocking the insert:
The policies look correct - there are 4 permissive INSERT policies including ones for anon and public roles. The issue must be with the Supabase client configuration. Let me check how the server client is set up:
The Supabase client setup looks correct. The issue might be that the request is being made from a Server Action, and it might be picking up authentication cookies that are causing it to use the authenticated role instead of anon. Let me check if there's a service role key available, or try using the browser client for the anonymous request instead:
The issue is that the server client might be picking up authentication cookies from a previous login, causing it to use the authenticated role which has a stricter policy requiring house_id to match the user's account.
Let me create a separate anonymous Supabase client specifically for public operations that doesn't use cookies:
I've created a separate anonymous Supabase client (getSupabaseAnonClient) that doesn't use cookies, and updated the submitTransportRequest function to use it. This ensures the request is made with the anon role regardless of whether the user has authentication cookies from a previous login. Try submitting the client request form again - it should work now.