From ca07dd0079f25fc186257e78ac65f1c63f556c44 Mon Sep 17 00:00:00 2001 From: DanielS Date: Fri, 3 Jul 2026 10:05:18 +0200 Subject: [PATCH] feat(setup): make isSetupNeeded check more robust using both auth listUsers and db count --- shop/lib/actions/setup.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/shop/lib/actions/setup.ts b/shop/lib/actions/setup.ts index dd35b04..045e23f 100644 --- a/shop/lib/actions/setup.ts +++ b/shop/lib/actions/setup.ts @@ -26,12 +26,28 @@ export type SmtpSetupData = { export async function isSetupNeeded(): Promise { try { const admin = createAdminClient() - const { count, error } = await admin + + // 1. Check if any user exists in Supabase Auth + const { data: authData, error: authError } = await admin.auth.admin.listUsers({ + perPage: 1 + }) + + if (authError) { + console.error('Error checking auth users list:', authError) + return false + } + + if (authData.users.length > 0) { + return false + } + + // 2. Check if any user exists in public.users table + const { count, error: dbError } = await admin .from('users') .select('*', { count: 'exact', head: true }) - if (error) { - console.error('Error checking setup status:', error) + if (dbError) { + console.error('Error checking users table status:', dbError) return false }