diff --git a/bun.lockb b/bun.lockb index caf76b7..a887a6d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index caa0599..e4f2fc7 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,7 @@ "prisma" ], "devDependencies": { - "@sveltejs/adapter-auto": "^3.0.1", - "@sveltejs/adapter-node": "^2.0.1", + "@sveltejs/adapter-node": "^2.0.2", "@sveltejs/enhanced-img": "^0.1.7", "@sveltejs/vite-plugin-svelte": "^3.0.1", "@tailwindcss/forms": "^0.5.7", diff --git a/src/app.d.ts b/src/app.d.ts index 7f3235d..aed052f 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -1,9 +1,17 @@ +import type { Auth as AuthType } from '$lib/server/auth'; +import type { PrismaClient } from '@prisma/client'; +import type { AuthRequest, Session } from 'lucia'; + // See https://kit.svelte.dev/docs/types#app // for information about these interfaces declare global { namespace App { // interface Error {} - // interface Locals {} + interface Locals { + db: PrismaClient; + auth: AuthRequest; + session: Session | null; + } interface PageData { seo?: { title?: string; @@ -16,6 +24,16 @@ declare global { // interface PageState {} // interface Platform {} } + + namespace Lucia { + type Auth = AuthType; + type DatabaseUserAttributes = { + username: string; + disallowedIngredients: string | null; + }; + // eslint-disable-next-line @typescript-eslint/ban-types + type DatabaseSessionAttributes = {}; + } } export {}; diff --git a/src/hooks.server.ts b/src/hooks.server.ts new file mode 100644 index 0000000..12484db --- /dev/null +++ b/src/hooks.server.ts @@ -0,0 +1,12 @@ +import { auth } from '$lib/server/auth'; +import { db } from '$lib/server/db'; + +import type { Handle } from '@sveltejs/kit'; + +export const handle: Handle = async ({ event, resolve }) => { + event.locals.db = db; + event.locals.auth = auth.handleRequest(event); + event.locals.session = await event.locals.auth.validate(); + + return resolve(event); +}; diff --git a/src/routes/+layout.server.ts b/src/routes/+layout.server.ts index f9639fa..6fb6d79 100644 --- a/src/routes/+layout.server.ts +++ b/src/routes/+layout.server.ts @@ -1,11 +1,8 @@ import type { LayoutServerLoad } from './$types'; -export const load = (async () => { +export const load = (async ({ locals }) => { return { - user: { - username: 'Carlos', - disallowedIngredients: ['chocolat'], - }, + user: locals.session?.user, seo: { title: 'CookConnect', meta: { diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 97c1d9c..7420903 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -7,6 +7,7 @@ import type { LayoutData } from './$types'; + import { enhance } from '$app/forms'; import { page } from '$app/stores'; export let data: LayoutData; @@ -49,15 +50,17 @@