Skip to content

Commit

Permalink
ajusts
Browse files Browse the repository at this point in the history
  • Loading branch information
andre-brandao committed Oct 11, 2024
1 parent ceee434 commit 947d39d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 73 deletions.
2 changes: 0 additions & 2 deletions src/hooks.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const handleSession: Handle = async ({ event, resolve }) => {
/* disallow access to PUBLIC_DOMAIN/tenant, this is optional */
const { host, pathname } = event.url

// TODOL: remove this
if (host === PUBLIC_DOMAIN) {
if (pathname.startsWith('/tenant')) {
error(404, { message: 'Not Found' })
Expand All @@ -29,7 +28,6 @@ const handleSession: Handle = async ({ event, resolve }) => {
error(404, { message: 'Not Found' })
}

console.log('tenant', tenant.tenantInfo)

event.locals.tenantDb = tenant.tenantDb
event.locals.tenantInfo = tenant.tenantInfo!
Expand Down
9 changes: 1 addition & 8 deletions src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ export const reroute: Reroute = ({ url }) => {
const i88nPathname = i18n.reroute()({ url })

const domain = getDomainAndType(url.host)

if (domain.type === 'appDomain') {
return i88nPathname
} else {
const tenantDomain = domain.domain

console.log(
'reroute: tenantDomain',
tenantDomain,
'i88nPathname',
i88nPathname,
)

return `/${tenantDomain}${i88nPathname}`
}
}
6 changes: 3 additions & 3 deletions src/lib/client/components/navbar/NavBar.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script lang="ts">
import type { User } from 'lucia'
import ThemeSwiter from './ThemeSwiter.svelte'
import ChangeLanguage from './ChangeLanguage.svelte'
import Cart from './Cart.svelte'
Expand All @@ -14,8 +13,9 @@
import { icons } from '$lib/client/utils/icons'
import { goto } from '$app/navigation'
const user = getUserContext()
export let tenantName = ""
const user = getUserContext()
</script>

<div class="drawer">
Expand Down Expand Up @@ -46,7 +46,7 @@
</div>
<div class="mx-2 flex-1 px-2">
<a href="/" class="btn btn-ghost text-xl max-sm:hidden">
{website.siteShortTitle}
{tenantName || website.siteShortTitle}
</a>
<Breadcrumbs />
</div>
Expand Down
8 changes: 4 additions & 4 deletions src/lib/server/services/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import nodemailer from 'nodemailer'

// import { env } from '$env/dynamic/private'
import { env } from '$env/dynamic/private'

import { website } from '$lib/config'

Expand All @@ -17,15 +17,15 @@ export async function sendMail(to: string, email: EmailOptions) {
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: process.env.GOOGLE_ACC_EMAIL,
pass: process.env.GOOGLE_ACC_PASSWORD,
user: env.GOOGLE_ACC_EMAIL,
pass: env.GOOGLE_ACC_PASSWORD,
},
})

const worked = await transporter.sendMail({
from: {
name: website.siteShortTitle,
address: process.env.GOOGLE_ACC_EMAIL || '',
address: env.GOOGLE_ACC_EMAIL || '',
},
to: to,
subject: email.subject,
Expand Down
118 changes: 65 additions & 53 deletions src/routes/(central)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,64 +24,76 @@
<Info message={form.message} success={form.success} />
{/if}

<label for="tenantName">Company Name</label>
<input
type="text"
id="tenantName"
name="tenantName"
class="input input-bordered"
required
value={form?.form?.tenantName ?? ''}
/>
{#if form?.data?.domain}
<!-- succsess your domain can be found here -->
<a
href="{form.data.domain}"
target="_blank"

class="btn mt-4"
>
{form.data.domain}
</a>
{:else}
<label for="tenantName">Company Name</label>
<input
type="text"
id="tenantName"
name="tenantName"
class="input input-bordered"
required
value={form?.form?.tenantName ?? ''}
/>

<label for="subdomain">Subdomain</label>
<input
type="text"
id="subdomain"
name="subdomain"
class="input input-bordered"
required
value={form?.form?.subdomain ?? ''}
/>
<label for="subdomain">Subdomain</label>
<input
type="text"
id="subdomain"
name="subdomain"
class="input input-bordered"
required
value={form?.form?.subdomain ?? ''}
/>

<label for="username">Username</label>
<input
type="text"
id="username"
name="username"
class="input input-bordered"
required
value={form?.form?.username ?? ''}
/>
<label for="username">Username</label>
<input
type="text"
id="username"
name="username"
class="input input-bordered"
required
value={form?.form?.username ?? ''}
/>

<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="input input-bordered"
required
value={form?.form?.email ?? ''}
/>
<label for="email">Email</label>
<input
type="email"
id="email"
name="email"
class="input input-bordered"
required
value={form?.form?.email ?? ''}
/>

<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
class="input input-bordered"
required
/>
<label for="password">Password</label>
<input
type="password"
id="password"
name="password"
class="input input-bordered"
required
/>

<label for="confirmPassword">Confirm Password</label>
<input
type="password"
id="confirmPassword"
name="confirmPassword"
class="input input-bordered"
required
/>
<label for="confirmPassword">Confirm Password</label>
<input
type="password"
id="confirmPassword"
name="confirmPassword"
class="input input-bordered"
required
/>

<button type="submit" class="btn mt-4">Submit</button>
<button type="submit" class="btn mt-4">Submit</button>
{/if}
</form>
</main>
2 changes: 1 addition & 1 deletion src/routes/(tenant)/[subdomain]/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
</script>


<NavBar>
<NavBar tenantName={data.tenantInfo.name}>
<slot />
</NavBar>
5 changes: 3 additions & 2 deletions src/routes/(tenant)/[subdomain]/products/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import type { PageServerLoad } from './$types'
import { product } from '$db/tenant/controller'
import { error } from '@sveltejs/kit'

export const load = (async ({ locals }) => {
export const load = (async ({ locals, url }) => {
console.log(locals)
if (!locals.tenantDb) {
return error(404, 'Tenant not found')
return error(404, 'Tenant not found' + url)
}

const products = await product(locals.tenantDb).queryCategorysWithProducts()
Expand Down

0 comments on commit 947d39d

Please sign in to comment.