-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsupabase-security-fix.sql
More file actions
53 lines (48 loc) · 1.54 KB
/
supabase-security-fix.sql
File metadata and controls
53 lines (48 loc) · 1.54 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
-- Security Fix for Syncodoro Functions
-- Run this to fix the search_path security warnings
-- Drop and recreate functions with proper security settings
DROP FUNCTION IF EXISTS public.handle_updated_at();
DROP FUNCTION IF EXISTS public.handle_new_user();
-- Create functions for automatic updated_at timestamps
CREATE OR REPLACE FUNCTION public.handle_updated_at()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = timezone('utc'::text, now());
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER
SET search_path = public;
-- Function to automatically create user profile and settings on signup
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS TRIGGER AS $$
BEGIN
INSERT INTO public.profiles (id, username, display_name)
VALUES (NEW.id, NULL, NEW.raw_user_meta_data->>'full_name');
INSERT INTO public.user_settings (
user_id,
pomodoro_length,
short_break_length,
long_break_length,
sessions_until_long_break,
auto_start_breaks,
auto_start_pomodoros,
sound_enabled,
sound_type,
notifications_enabled
)
VALUES (
NEW.id,
25, -- default pomodoro length (minutes)
5, -- default short break length (minutes)
15, -- default long break length (minutes)
4, -- default sessions until long break
false, -- default auto start breaks
false, -- default auto start pomodoros
true, -- default sound enabled
'beep', -- default sound type
true -- default notifications enabled
);
RETURN NEW;
END;
$$ LANGUAGE plpgsql SECURITY DEFINER
SET search_path = public;