From ea0ce134fe26b36847c2426c9835095d03033985 Mon Sep 17 00:00:00 2001 From: Dan Mihailescu Date: Wed, 18 Dec 2024 10:11:29 -0500 Subject: [PATCH] fixed all commented issues --- prisma/dev.db | Bin 49152 -> 49152 bytes prisma/schema.prisma | 4 +-- src/lib/server/lucia.ts | 44 +++++++++++++++---------------- src/routes/+page.server.ts | 4 +-- src/routes/login/+page.server.ts | 20 +++++++------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/prisma/dev.db b/prisma/dev.db index 4d6eb2ee49602e06b1152ed88858370821600a4a..86ecbef1a1c7a349d239bde8bd6c1be2c0b51769 100644 GIT binary patch delta 322 zcmZo@U~Xt&o*>O=G*QNx(P(4Bl6(;kULgklrTq4MPx$KilzC6^=JE<{R#f=K;}prk z7R$=YYM-B$m7bKAlVo0=Vp>*Qke-=aQI?o)nvqpuoSAA=Qkn*&Q!-2Q8K;z-y`jiB z`If(c3WS`T7cc1)$qq55tRN%XEHkyL+_>00x2Q0ysH7-2JvBKe+o;UAproQa187A~ zW{ - return { - email: attributes.email - } - } + sessionCookie: { + attributes: { + secure: process.env.NODE_ENV === 'production' + } + }, + getUserAttributes: (attributes) => { + return { + email: attributes.email + }; + } }); -declare module "lucia" { - interface Register { - Lucia: typeof Lucia; - DatabaseUserAttributes: DatabaseUserAttributes - } +declare module 'lucia' { + interface Register { + Lucia: typeof Lucia; + DatabaseUserAttributes: DatabaseUserAttributes; + } } interface DatabaseUserAttributes { - email: string + email: string; } -export type Auth = typeof auth; \ No newline at end of file +export type Auth = typeof auth; diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 145d816..7c3b840 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,6 +1,6 @@ import { prisma } from '$lib/server/prisma'; -import type { Session } from 'lucia'; -export async function load(event: Session) { +export async function load(event) { + console.log(event.userId); const userId = event.userId; if (!userId) { return { diff --git a/src/routes/login/+page.server.ts b/src/routes/login/+page.server.ts index 6c6e9a1..dc69fae 100644 --- a/src/routes/login/+page.server.ts +++ b/src/routes/login/+page.server.ts @@ -1,7 +1,7 @@ import { logger } from '$lib/server/logger'; import { prisma } from '$lib/server/prisma'; import { error, redirect, type Actions } from '@sveltejs/kit'; -import { Argon2id } from "oslo/password" +import { Argon2id } from 'oslo/password'; import { auth } from '$lib/server/lucia.js'; export const actions = { @@ -19,12 +19,12 @@ export const actions = { logger.error('User not found! ${user}'); return error(401); } - const pw = form.get('password') as string; - if(!pw) { - return error(401, 'Password is required') + const password = form.get('password') as string; + if (!password) { + return error(401, 'Password is required'); } - const validPassword = await new Argon2id().verify(user.password,pw); - if(!validPassword) { + const validPassword = await new Argon2id().verify(user.password, password); + if (!validPassword) { return error(400, 'Password is incorrect!'); } const session = await auth.createSession(user.id, []); @@ -36,14 +36,13 @@ export const actions = { redirect(302, '/'); }, - - register: async (event) => { const form = await event.request.formData(); if (!form.has('email') || !form.has('name') || !form.has('password')) { return error(400); } - const hashedPassword = await new Argon2id().hash(form.get('password') as string) + const password = form.get('password') as string; + const hashedPassword = await new Argon2id().hash(password); const user = await prisma.user.create({ data: { email: form.get('email') as string, @@ -61,6 +60,5 @@ export const actions = { maxAge: 120 }); redirect(302, '/'); - } -} satisfies Actions; \ No newline at end of file +} satisfies Actions;