-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase_rls_setup.sql
More file actions
25 lines (21 loc) · 894 Bytes
/
supabase_rls_setup.sql
File metadata and controls
25 lines (21 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- 1. Enable Row Level Security
ALTER TABLE public.users ENABLE ROW LEVEL SECURITY;
-- 2. Create Policy for Inserting Data
-- This allows authenticated users to insert a row, but ONLY if the id matches their auth.uid()
CREATE POLICY "Users can insert their own profile"
ON public.users FOR INSERT
WITH CHECK (auth.uid() = id);
-- 3. Create Policy for Updating Data
-- This allows authenticated users to update their own row
CREATE POLICY "Users can update their own profile"
ON public.users FOR UPDATE
USING (auth.uid() = id);
-- 4. Create Policy for Viewing Data
-- This allows authenticated users to view their own profile
CREATE POLICY "Users can view their own profile"
ON public.users FOR SELECT
USING (auth.uid() = id);
-- 5. (Optional) Allow public read access to avatars/names if needed
-- CREATE POLICY "Public profiles are viewable"
-- ON public.users FOR SELECT
-- USING (true);