-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-profiles-approach.js
More file actions
113 lines (93 loc) · 3.62 KB
/
Copy pathtest-profiles-approach.js
File metadata and controls
113 lines (93 loc) · 3.62 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
104
105
106
107
108
109
110
111
112
113
// Test using profiles table instead of users table
const { createClient } = require('@supabase/supabase-js');
async function testProfilesApproach() {
console.log('Testing profiles table approach...');
const supabase = createClient(
process.env.NEXT_PUBLIC_SUPABASE_URL,
process.env.SUPABASE_SERVICE_ROLE_KEY,
{
auth: {
autoRefreshToken: false,
persistSession: false,
},
}
);
try {
// First, let's see what the profiles table structure looks like
console.log('1. Testing profiles table structure...');
// Try to insert a profile with minimal data
const testUserId = 'f0000000-0000-0000-0000-000000000001'; // Valid UUID
const testEmail = `test-profile-approach-${Date.now()}@example.com`;
console.log('2. Creating profile with minimal data...');
console.log(' User ID:', testUserId);
console.log(' Email:', testEmail);
// Try creating just with id and email
const { data, error } = await supabase
.from('profiles')
.insert({
id: testUserId,
email: testEmail,
})
.select()
.single();
if (error) {
console.error('❌ Profile creation failed:', error);
console.error(' Error code:', error.code);
console.error(' Error message:', error.message);
console.error(' Error details:', error.details);
} else {
console.log('✅ Profile created successfully:', data);
// Now test organization creation with this profile ID
console.log('\n3. Testing organization creation with profile ID...');
const orgName = `Test Org ${Date.now()}`;
const orgSlug = `test-org-${Date.now()}`;
const { data: orgData, error: orgError } = await supabase
.from('organizations')
.insert({
name: orgName,
slug: orgSlug,
created_by: testUserId, // Use the profile ID
})
.select()
.single();
if (orgError) {
console.error('❌ Organization creation failed:', orgError);
} else {
console.log('✅ Organization created successfully:', orgData);
// Test membership creation
console.log('\n4. Testing membership creation...');
const { data: memberData, error: memberError } = await supabase
.from('memberships')
.insert({
user_id: testUserId,
organization_id: orgData.id,
role: 'owner',
accepted_at: new Date().toISOString(),
})
.select()
.single();
if (memberError) {
console.error('❌ Membership creation failed:', memberError);
} else {
console.log('✅ Membership created successfully:', memberData);
}
// Clean up
await supabase.from('memberships').delete().eq('organization_id', orgData.id);
await supabase.from('organizations').delete().eq('id', orgData.id);
console.log('✅ Organization and membership cleaned up');
}
// Clean up profile
await supabase.from('profiles').delete().eq('id', testUserId);
console.log('✅ Profile cleaned up');
}
// Test if the issue is with using an existing auth user ID
console.log('\n5. Testing with a real auth user ID...');
// Let's see if we can find any existing auth users to use their IDs
// Since we can't query auth.users directly, let's try a different approach
} catch (error) {
console.error('General error:', error);
}
}
// Load environment variables
require('dotenv').config({ path: '.env.local' });
testProfilesApproach();