supabase client expose error

Hi all, new to supabase, being working with the supabase client and when making an update to a table record which has a RLS policy that only let's owners update their records the record is not updated as expected but i get no error. The response is { error: null, data: [], count: null, status: 200, statusText: 'OK' }

I was expecting to get an error indicating that i cannot update the record. Is this the expected behaviour?

Here is the relevant code:
table and RLS
CREATE TABLE "public"."user_posts"(
    id uuid DEFAULT uuid_generate_v4() PRIMARY KEY,
    user_id uuid REFERENCES auth.users(id) ON DELETE CASCADE,
    title varchar(255) NOT NULL,
    body text NOT NULL,
    created_at timestamp with time zone NOT NULL DEFAULT now(),
    updated_at timestamp with time zone NOT NULL DEFAULT now()
);

ALTER TABLE public.user_posts ENABLE ROW LEVEL SECURITY;

CREATE POLICY "Allow users to create their own posts" ON user_posts
    FOR INSERT TO authenticated
        WITH CHECK ((
            SELECT
                auth.uid()) = user_id);

CREATE POLICY "Allow users to update their own posts" ON user_posts
    FOR UPDATE TO authenticated
        USING ((
            SELECT
                auth.uid()) = user_id)
            WITH CHECK ((
                SELECT
                    auth.uid()) = user_id);

And the client code:
... 
    supabase.auth.setSession({ access_token: accessToken, refresh_token: refreshToken })

    const { data: { user } } = await supabase.auth.getUser();

    const response = await supabase
        .from('user_posts')
        .update([
            {
                body: faker.lorem.text(),
                title: faker.lorem.sentence(3),
            }
        ])
        .eq('id', id)
        .select();

    if (response.error) {
        throw new Error(response.error.message);
    }

    return response;
...
Was this page helpful?