From baeabb79901ca5579ce8d9628e1d06dae372e8b0 Mon Sep 17 00:00:00 2001 From: 230417 <230417@epvc.pt> Date: Tue, 10 Mar 2026 16:50:51 +0000 Subject: [PATCH] . --- web/src/lib/check_db.ts | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/web/src/lib/check_db.ts b/web/src/lib/check_db.ts index bd80f29..ea7b691 100644 --- a/web/src/lib/check_db.ts +++ b/web/src/lib/check_db.ts @@ -8,8 +8,7 @@ const supabase = createClient(supabaseUrl, supabaseAnonKey); async function check() { console.log("Checking insert..."); - // Auth with a test user or just try anon insert. - // If it requires user login, we can login with the previously created user: test_shop_1773154696588@test.com + // Auth with a test user const { data: authData, error: authErr } = await supabase.auth.signInWithPassword({ email: 'test_shop_1773154696588@test.com', password: 'Password123!' @@ -17,12 +16,23 @@ async function check() { if (authErr && !authData?.user) { console.error("Login err:", authErr); + return; } const userId = authData.user?.id; - const { data: shops } = await supabase.from('shops').select('id').eq('owner_id', userId).limit(1); + console.log("User id:", userId); + + let { data: shops } = await supabase.from('shops').select('id').eq('owner_id', userId).limit(1); + if (!shops || shops.length === 0) { - console.error("No shops found for user", userId); + console.log("Creating new shop for user..."); + const res = await supabase.from('shops').insert([{ name: 'Test Shop RLS', owner_id: userId, rating: 5 }]).select(); + console.log("Create shop response:", res); + shops = res.data; + } + + if (!shops || shops.length === 0) { + console.error("Still no shop found!"); return; } @@ -30,11 +40,17 @@ async function check() { console.log("Attempting to insert service to shop:", shopId); - const { data, error } = await supabase.from('services').insert([ + const { data: svc, error: svcErr } = await supabase.from('services').insert([ { shop_id: shopId, name: 'Test Service', price: 10, duration: 15 } ]).select(); - console.log("Insert result:", { data, error }); + console.log("Insert service result:", svcErr || "SUCCESS", svc); + + const { data: bbr, error: bbrErr } = await supabase.from('barbers').insert([ + { shop_id: shopId, name: 'Test Barber' } + ]).select(); + + console.log("Insert barber result:", bbrErr || "SUCCESS", bbr); } check();