From 866c5522f2835d3ed5ceae34ea1e2a1d6f6d6047 Mon Sep 17 00:00:00 2001 From: DanielS Date: Tue, 11 Aug 2026 17:27:14 +0200 Subject: [PATCH] fix(setup): make SMTP optional and adjust setup check --- shop/components/SetupWizard.tsx | 9 ++++---- shop/lib/actions/setup.ts | 39 +++++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/shop/components/SetupWizard.tsx b/shop/components/SetupWizard.tsx index 7f0ba2a..172a499 100644 --- a/shop/components/SetupWizard.tsx +++ b/shop/components/SetupWizard.tsx @@ -44,14 +44,13 @@ export function SetupWizard() { adminForm.firstName.trim().length > 0 && adminForm.lastName.trim().length > 0 - // Validation checks for SMTP form + // Validation checks for SMTP form (optional step) const isSmtpFormValid = - smtpForm.host.trim().length > 0 && - !isNaN(Number(smtpForm.port)) && - smtpForm.user.trim().length > 0 + smtpForm.host.trim().length === 0 || + (!isNaN(Number(smtpForm.port)) && smtpForm.user.trim().length > 0) const handleFinishSetup = async () => { - if (!isAdminFormValid || !isSmtpFormValid) return + if (!isAdminFormValid) return setLoading(true) setErrorMsg('') diff --git a/shop/lib/actions/setup.ts b/shop/lib/actions/setup.ts index 045e23f..c0bd7cc 100644 --- a/shop/lib/actions/setup.ts +++ b/shop/lib/actions/setup.ts @@ -34,10 +34,10 @@ export async function isSetupNeeded(): Promise { if (authError) { console.error('Error checking auth users list:', authError) - return false + return true } - if (authData.users.length > 0) { + if (authData && authData.users && authData.users.length > 0) { return false } @@ -48,13 +48,13 @@ export async function isSetupNeeded(): Promise { if (dbError) { console.error('Error checking users table status:', dbError) - return false + return true } return count === 0 } catch (e) { console.error('Exception checking setup status:', e) - return false + return true } } @@ -113,22 +113,23 @@ export async function completeSetup( console.error('Error updating admin profile:', profileError) } - // 5. Store SMTP configuration in public.settings - const { error: smtpError } = await admin - .from('settings') - .upsert({ - id: 'smtp', - host: smtpData.host, - port: smtpData.port, - secure: smtpData.secure, - user: smtpData.user, - pass: smtpData.pass, - updated_at: new Date().toISOString(), - }) + // 5. Store SMTP configuration in public.settings (optional) + if (smtpData.host && smtpData.host.trim().length > 0) { + const { error: smtpError } = await admin + .from('settings') + .upsert({ + id: 'smtp', + host: smtpData.host, + port: smtpData.port, + secure: smtpData.secure, + user: smtpData.user, + pass: smtpData.pass, + updated_at: new Date().toISOString(), + }) - if (smtpError) { - console.error('Error saving SMTP settings:', smtpError) - return { success: false, error: `Fehler beim Speichern der SMTP-Einstellungen: ${smtpError.message}` } + if (smtpError) { + console.error('Error saving SMTP settings:', smtpError) + } } revalidatePath('/')