feat(setup): make isSetupNeeded check more robust using both auth listUsers and db count
This commit is contained in:
@@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user