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
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.
Also if you have select on the insert you will need to have a select policy.
Thanks, it is working now.