feat(setup): make isSetupNeeded check more robust using both auth listUsers and db count

This commit is contained in:
DanielS
2026-07-03 10:05:18 +02:00
parent 233b9f135d
commit ca07dd0079

View File

@@ -26,12 +26,28 @@ export type SmtpSetupData = {
export async function isSetupNeeded(): Promise<boolean> { export async function isSetupNeeded(): Promise<boolean> {
try { try {
const admin = createAdminClient() 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') .from('users')
.select('*', { count: 'exact', head: true }) .select('*', { count: 'exact', head: true })
if (error) { if (dbError) {
console.error('Error checking setup status:', error) console.error('Error checking users table status:', dbError)
return false return false
} }