So I enable RLS by using the template and trying to limit access to only logged in user
CREATE POLICY "Enable read access for authenticated users" ON "public"."item"
AS PERMISSIVE FOR SELECT
TO authenticated
USING (true)
A supabase client is like so
// utils.js
export function supabaseClient(options, token) {
const options = {
...options,
schema: schema || 'public',
global: {
headers: {
Authorization: `Bearer ${token}`,
},
},
};
return createClient(
process.env.NX_SUPABASE_URL,
process.env.NX_SUPABASE_ANON_KEY,
// process.env.NX_SUPABASE_SERVICE_ROLE_KEY,
options
);
}
// component,js
const supabase = supabaseClient(options);
const { count, error: errorCount } = await supabase
.from('item')
.select(*);
After a successful login, I pass the token to supabase client and the token is present on the options object. The issue is the data empty and no error.
If I add the anon role like so, the data is present but I don't want that behavior
CREATE POLICY "Enable read access for authenticated users" ON "public"."item"
AS PERMISSIVE FOR SELECT
TO authenticated, anon
USING (true)
So how can I limit access to the table with ANON_KEY and access_token to only authenticated user only? I search on the doc but nothing I can find useful