-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_google_oauth.sql
More file actions
38 lines (35 loc) · 1.15 KB
/
fix_google_oauth.sql
File metadata and controls
38 lines (35 loc) · 1.15 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
-- Fix profiles table structure for Google OAuth
-- Add the missing columns that the handle_new_user function expects
ALTER TABLE public.profiles
ADD COLUMN IF NOT EXISTS full_name TEXT,
ADD COLUMN IF NOT EXISTS avatar_url TEXT,
ADD COLUMN IF NOT EXISTS phone TEXT;
-- Fix the handle_new_user function to work with the current schema
DROP TRIGGER IF EXISTS on_auth_user_created ON auth.users;
DROP FUNCTION IF EXISTS public.handle_new_user();
CREATE OR REPLACE FUNCTION public.handle_new_user()
RETURNS TRIGGER
LANGUAGE plpgsql
SECURITY DEFINER SET search_path = public
AS $$
BEGIN
INSERT INTO public.profiles (id, email, phone, full_name, avatar_url)
VALUES (
NEW.id,
NEW.email,
NEW.phone,
COALESCE(NEW.raw_user_meta_data ->> 'full_name', ''),
COALESCE(NEW.raw_user_meta_data ->> 'avatar_url', '')
);
RETURN NEW;
EXCEPTION
WHEN OTHERS THEN
-- Log the error but don't fail the auth process
RAISE WARNING 'Error in handle_new_user: %', SQLERRM;
RETURN NEW;
END;
$$;
-- Re-enable the trigger on auth.users
CREATE TRIGGER on_auth_user_created
AFTER INSERT ON auth.users
FOR EACH ROW EXECUTE FUNCTION public.handle_new_user();