Skip to content

Commit

Permalink
fix: hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-brandao committed Oct 10, 2024
1 parent fa704ef commit 1a9b01f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
30 changes: 15 additions & 15 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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);

Expand Down Expand Up @@ -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,
Expand Down
7 changes: 6 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
}
Expand Down

0 comments on commit 1a9b01f

Please sign in to comment.