-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapply_rls_policies.sql
More file actions
66 lines (54 loc) · 2.4 KB
/
Copy pathapply_rls_policies.sql
File metadata and controls
66 lines (54 loc) · 2.4 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
-- Apply RLS policies manually - copy and paste this into Supabase SQL Editor
-- ===== PROFILES TABLE POLICIES =====
-- Drop existing policies if they exist
DROP POLICY IF EXISTS "Allow anonymous profile creation" ON profiles;
DROP POLICY IF EXISTS "Allow users to insert their own profiles" ON profiles;
DROP POLICY IF EXISTS "Allow users to view their own profiles" ON profiles;
DROP POLICY IF EXISTS "Allow users to update their own profiles" ON profiles;
-- Create policy to allow anonymous users to insert profiles (for guest quotes)
CREATE POLICY "Allow anonymous profile creation" ON profiles
FOR INSERT
TO anon
WITH CHECK (true);
-- Create policy to allow authenticated users to insert their own profiles
CREATE POLICY "Allow users to insert their own profiles" ON profiles
FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id);
-- Create policy to allow users to view their own profiles
CREATE POLICY "Allow users to view their own profiles" ON profiles
FOR SELECT
TO authenticated
USING (auth.uid() = user_id);
-- Create policy to allow users to update their own profiles
CREATE POLICY "Allow users to update their own profiles" ON profiles
FOR UPDATE
TO authenticated
USING (auth.uid() = user_id)
WITH CHECK (auth.uid() = user_id);
-- ===== QUOTES TABLE POLICIES =====
-- Drop existing policies if they exist
DROP POLICY IF EXISTS "Allow anonymous quote submissions" ON quotes;
DROP POLICY IF EXISTS "Allow authenticated users to insert quotes" ON quotes;
DROP POLICY IF EXISTS "Allow users to view their own quotes" ON quotes;
DROP POLICY IF EXISTS "Allow anonymous quote viewing" ON quotes;
-- Create policy to allow anonymous users to insert quotes
CREATE POLICY "Allow anonymous quote submissions" ON quotes
FOR INSERT
TO anon
WITH CHECK (true);
-- Create policy to allow authenticated users to insert their own quotes
CREATE POLICY "Allow authenticated users to insert quotes" ON quotes
FOR INSERT
TO authenticated
WITH CHECK (auth.uid() = user_id OR user_id IS NULL);
-- Create policy to allow users to select their own quotes
CREATE POLICY "Allow users to view their own quotes" ON quotes
FOR SELECT
TO authenticated
USING (auth.uid() = user_id);
-- Allow anonymous users to select quotes (for immediate feedback after submission)
CREATE POLICY "Allow anonymous quote viewing" ON quotes
FOR SELECT
TO anon
USING (true);