This commit is contained in:
2026-03-10 16:50:51 +00:00
parent aeb1b17c63
commit baeabb7990

View File

@@ -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();