diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 15a341d..f4f7b87 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -103,7 +103,16 @@ const setupCheckHandle: Handle = async ({ event, resolve }) => { if (error) { console.error('Error checking for existing users:', error); - // On error, continue without redirect (fail open) + // If table doesn't exist or other DB error, assume setup is needed + // Common errors: relation "members" does not exist, permission denied + if (error.message?.includes('does not exist') || + error.message?.includes('relation') || + error.code === '42P01' || // undefined_table + error.code === 'PGRST204') { // no rows (table might not exist) + setupCheckCache = { needsSetup: true, checkedAt: now }; + throw redirect(303, '/setup'); + } + // For other errors, fail open to avoid blocking the app return resolve(event); } @@ -119,6 +128,8 @@ const setupCheckHandle: Handle = async ({ event, resolve }) => { throw err; } console.error('Error in setup check:', err); + // On unexpected errors, redirect to setup as a safe default + throw redirect(303, '/setup'); } return resolve(event);