Repository navigation
Expand file tree
/
Copy pathdebug_user_creation.sql
More file actions
103 lines (92 loc) · 2.38 KB
/
Copy pathdebug_user_creation.sql
File metadata and controls
103 lines (92 loc) · 2.38 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
-- Debug script to identify user creation issues
-- Run this in the Supabase SQL editor to diagnose the problem
-- 1. Check the current profiles table structure
SELECT
column_name,
data_type,
is_nullable,
column_default,
character_maximum_length
FROM information_schema.columns
WHERE table_name = 'profiles'
AND table_schema = 'public'
ORDER BY ordinal_position;
-- 2. Check for any constraints that might be failing
SELECT
tc.constraint_name,
tc.constraint_type,
cc.column_name,
tc.table_name
FROM information_schema.table_constraints tc
JOIN information_schema.constraint_column_usage cc ON tc.constraint_name = cc.constraint_name
WHERE tc.table_name = 'profiles'
AND tc.table_schema = 'public';
-- 3. Check existing triggers on auth.users
SELECT
trigger_name,
event_manipulation,
action_timing,
action_statement
FROM information_schema.triggers
WHERE event_object_table = 'users'
AND trigger_schema = 'auth';
-- 4. Test what happens when we try to insert a user manually
-- First, let's see if we can insert into profiles directly
DO $$
BEGIN
-- Try to insert a test profile
INSERT INTO profiles (id, email, first_name, last_name, personalization_enabled, last_login_at, loyalty_tier)
VALUES (
gen_random_uuid(),
'debug.test@example.com',
'Debug',
'Test',
true,
NOW(),
'standard'
);
RAISE NOTICE 'Direct profile insertion successful';
-- Clean up
DELETE FROM profiles WHERE email = 'debug.test@example.com';
EXCEPTION WHEN OTHERS THEN
RAISE NOTICE 'Direct profile insertion failed: % %', SQLSTATE, SQLERRM;
END $$;
-- 5. Check if there are any existing users that might cause conflicts
SELECT
id,
email,
created_at,
email_confirmed_at,
raw_user_meta_data
FROM auth.users
WHERE email = 'test.user@pf.dev'
LIMIT 1;
-- 6. Check if there are any profiles with this email already
SELECT
id,
email,
first_name,
last_name,
created_at
FROM profiles
WHERE email = 'test.user@pf.dev'
LIMIT 1;
-- 7. Check the handle_new_user function
SELECT
routine_name,
routine_definition
FROM information_schema.routines
WHERE routine_name = 'handle_new_user'
AND routine_schema = 'public';
-- 8. Check if there are any policies that might be blocking the insertion
SELECT
schemaname,
tablename,
policyname,
permissive,
roles,
cmd,
qual
FROM pg_policies
WHERE tablename = 'profiles'
AND schemaname = 'public';