Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Add RLS policy template to "Enable users to view their own data only" (#28778)

Tristan Rhodescf04f86ab79d
diff --git a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
index f59eb3d10d0..f941cf82d19 100644
--- a/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
+++ b/apps/studio/components/interfaces/Auth/Policies/PolicyEditorModal/PolicyEditorModal.constants.ts
@@ -172,6 +172,25 @@ for select using (
command: 'SELECT',
roles: [],
},
+ {
+ id: 'policy-9',
+ preview: false,
+ templateName: 'Allow users to only view their own data',
+ description: 'Restrict users to reading only their own data.',
+ statement: `
+create policy "Enable users to view their own data only"
+on "${schema}"."${table}"
+for select
+to authenticated
+using (
+ (select auth.uid()) = user_id
+);`.trim(),
+ name: 'Enable users to view their own data only',
+ definition: '(select auth.uid()) = user_id',
+ check: '',
+ command: 'SELECT',
+ roles: ['authenticated'],
+ },
]
export const getRealtimePolicyTemplates = (): PolicyTemplate[] => {