From f1a871ae19914350f1e95e6d88f65a95e7b7bea8 Mon Sep 17 00:00:00 2001 From: rishikanthc Date: Sat, 19 Oct 2024 12:15:30 -0700 Subject: [PATCH] fix(wizard): simplify logic to check wizard --- src/hooks.server.ts | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 130e1be..664b987 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -55,24 +55,14 @@ export const authentication: Handle = async ({ event, resolve }) => { }; export const configuration: Handle = async ({ event, resolve }) => { - try { - // Try to fetch settings collection - const settings = await event.locals.pb.collection('settings').getList(1, 1); - // Check if the collection is empty or wizard hasn't been completed - const condition = (settings.items.length <= 0) || settings.items[0]?.wizard; + const collections = await event.locals.pb.collections.getFullList(); + const hasSettings = collections.some(collection => collection.name === 'settings'); - if (condition && !event.url.pathname.endsWith('/wizard') && !event.url.pathname.startsWith('/api/')) { - // Redirect to wizard if conditions are met - console.log("Redirecting to wizard <-------------"); - throw redirect(307, '/wizard'); - } - } catch (error) { - // If the settings collection doesn't exist or there's an error, redirect to wizard - console.error('Error fetching settings collection or collection does not exist:', error); - if (!event.url.pathname.endsWith('/wizard') && !event.url.pathname.startsWith('/api/')) { - throw redirect(307, '/wizard'); - } + if (hasSettings || event.url.pathname.endsWith('/wizard')) { + resolve(event); + } else { + throw redirect(307, '/wizard'); } // Resolve event if no issues