From 1a9b01f1a8f98e5b8b87a4d640b401df59cd6581 Mon Sep 17 00:00:00 2001 From: andre-brandao <82166576+andre-brandao@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:24:31 -0300 Subject: [PATCH] fix: hooks --- src/hooks.server.ts | 30 +++++++++++++++--------------- src/hooks.ts | 7 ++++++- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/src/hooks.server.ts b/src/hooks.server.ts index bd84f7c..65a578a 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -2,6 +2,11 @@ import { i18n } from '$lib/i18n/i18n' import { getLuciaForTenant } from '$lib/server/auth' import { error, type Handle } from '@sveltejs/kit' import { sequence } from '@sveltejs/kit/hooks' +import { createContext } from '$trpc/context' +import { router } from '$trpc/router' +import { createTRPCHandle } from 'trpc-sveltekit' +import { PUBLIC_DOMAIN } from '$env/static/public' +import { getTenant } from '$lib/server/utils/getTenantInformation' // import { bugReport } from '$db/controller' @@ -10,19 +15,19 @@ const handleSession: Handle = async ({ event, resolve }) => { const { host, pathname } = event.url // TODOL: remove this - // if (host === PUBLIC_DOMAIN) { - // if (pathname.startsWith('/tenant')) { - // error(404, { message: 'Not Found' }) - // } else { - // return resolve(event) - // } - // } + if (host === PUBLIC_DOMAIN) { + if (pathname.startsWith('/tenant')) { + error(404, { message: 'Not Found' }) + } else { + return resolve(event) + } + } /* if no database returned for given subdomain or custom domain then the tenant does not exist */ const tenant = await getTenant(host) - if (!tenant) { - error(404, { message: 'Not Found' }) - } + // if (!tenant) { + // error(404, { message: 'Not Found' }) + // } console.log('tenant', tenant.tenantInfo); @@ -62,11 +67,6 @@ const handleSession: Handle = async ({ event, resolve }) => { return resolve(event) } -import { createContext } from '$trpc/context' -import { router } from '$trpc/router' -import { createTRPCHandle } from 'trpc-sveltekit' -import { PUBLIC_DOMAIN } from '$env/static/public' -import { getTenant } from '$lib/server/utils/getTenantInformation' const handleTRPC = createTRPCHandle({ router, diff --git a/src/hooks.ts b/src/hooks.ts index 98c8ecf..58e831b 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -15,7 +15,12 @@ export const reroute: Reroute = ({ url }) => { } else { const tenantDomain = domain.domain - console.log('reroute: tenantDomain', tenantDomain) + console.log( + 'reroute: tenantDomain', + tenantDomain, + 'i88nPathname', + i88nPathname, + ) return `/${tenantDomain}${i88nPathname}` }