S
Supabase2w ago
C&L

Why can't I insert a row in my table which is in a new schema?

Hi all, I am connecting the schema landingpage from my Supabase database to my website where anon users can insert a row in the table visits. Row Level Security is enabled. I have the below policy: alter policy "Allow anon insert" on "landingpage"."visits" to anon with check ( true ); And below is the js code on my website: import { createClient } from 'https://cdn.jsdelivr.net/npm/@supabase/supabase-js/+esm'; const supabase = createClient( supabaseUrl, supabaseKey, { db: { schema: "landingpage" } } ); const { error } = await supabase .from('visits') .insert({ country: countryName }) .select() if (error) console.error('Insert error:', error) But I get the below error message: Insert error: {code: '42501', details: null, hint: null, message: 'permission denied for table visits'} (anonymous) @ index.js:102 What could be the issue? I would appreciate it if anyone could help me in this.
3 Replies
garyaustin
garyaustin2w ago
You did not do your grants correctly. https://supabase.com/docs/guides/api/using-custom-schemas
Using Custom Schemas | Supabase Docs
You need additional steps to use custom database schemas with data APIs.
garyaustin
garyaustin2w ago
Also if you have select on the insert you will need to have a select policy.
C&L
C&LOP2w ago
Thanks, it is working now.

Did you find this page helpful?