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 }