Muneeb
Muneeb

Reputation: 93

new row violates row-level security policy for table "tasks"

I am new to supabase and am trying to integrate my Todo App made with BlueBase, a Framework based on react and react native. And, I am facing such a problem.

CreateTaskScreen.tsx

import React from 'react';

import CreateTaskForm from '../../components/CreateTaskForm';

export const CreateTaskScreen = () => {
    return (
        <CreateTaskForm />
    );
};

CreateTaskScreen.displayName = 'CreateTaskScreen';

index.ts

export * from './CreateTaskScreen';

import { CreateTaskScreen } from './CreateTaskScreen';
export default CreateTaskScreen;

enter image description here

Upvotes: 6

Views: 16602

Answers (5)

euphydev
euphydev

Reputation: 1

I found a solution on my end, basically, I just added 2 Policies for my USERS table, for INSERT and SELECT. Let me know if this works!

INSERT - Enable insert for authenticated users only

SELECT - Enable users to view their own data only

The two policies, INSERT and SELECT in an admin panel

Upvotes: 0

Shashank Hegde
Shashank Hegde

Reputation: 2589

Just issue this command

alter table "storage"."objects" DISABLE row level security;

Upvotes: -2

Aman Raj
Aman Raj

Reputation: 21

I was getting same error. Used pgsql. After lots of research i got to know that we need to add trigger for the respective table. enter image description here

-- Drop the trigger function
DROP FUNCTION set_tenant_id_on_insert;

-- Create the trigger function
CREATE OR REPLACE FUNCTION set_tenant_id_on_insert()
RETURNS TRIGGER AS $$
BEGIN
    NEW.tenant_id := current_setting('my.tenant_id');
    RETURN NEW;
END;
$$ LANGUAGE plpgsql; 

-- Register the trigger
CREATE TRIGGER insert_tenant_id_into_credentials
BEFORE INSERT ON credentials
FOR EACH ROW
EXECUTE FUNCTION set_tenant_id_on_insert();

Upvotes: 0

Muneeb
Muneeb

Reputation: 93

Enter the API URL and API Key carefully. It will resolve your

new row violates row-level security policy for table "tasks"

error. And also follow the blue base documentation to create a table carefully. Enter Table Name, Type, and Default Value carefully. Also, the default value of id is uuid_generate_v4(). You can see it in the suggestions.

enter image description here

Upvotes: 2

Purwanto
Purwanto

Reputation: 71

Adding a policy seems like the best way, with this you don't need to disable the RLS policy and don't need to use a secret key which is very unsafe for your data.

To do this,

  1. Go to "Authentication" > "Policies" > Select the "New Policy" table enter image description here

  2. Then add from the template for policy insert data. enter image description here

  3. Follow the next steps enter image description here

  4. Review your policy

  5. Save New Policy

Upvotes: 6

Related Questions