From 9ab6454ab0a43f21e8ac974eefcdb8864161d283 Mon Sep 17 00:00:00 2001 From: Bit-Barron Date: Tue, 29 Oct 2024 00:36:59 +0100 Subject: [PATCH] clean up --- src/hooks.server.ts | 6 ++++-- src/routes/(auth)/login/+page.server.ts | 2 -- src/routes/(auth)/register/+page.server.ts | 12 +++++++++--- src/routes/(auth)/reset-password/+page.server.ts | 0 src/routes/(auth)/reset-password/+page.svelte | 0 5 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 src/routes/(auth)/reset-password/+page.server.ts create mode 100644 src/routes/(auth)/reset-password/+page.svelte diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 4288f61..4fea9a7 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -13,17 +13,19 @@ export const handle: Handle = async ({ event, resolve }) => { if (session && session.fresh) { const sessionCookie = lucia.createSessionCookie(session.id); event.cookies.set(sessionCookie.name, sessionCookie.value, { - path: '.', + path: '/', ...sessionCookie.attributes }); } + if (!session) { const sessionCookie = lucia.createBlankSessionCookie(); event.cookies.set(sessionCookie.name, sessionCookie.value, { - path: '.', + path: '/', ...sessionCookie.attributes }); } + event.locals.user = user; event.locals.session = session; return resolve(event); diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts index fcef4a6..f78b4e2 100644 --- a/src/routes/(auth)/login/+page.server.ts +++ b/src/routes/(auth)/login/+page.server.ts @@ -19,8 +19,6 @@ export const actions: Actions = { where: { email } }); - console.log(user); - const validPassword = user ? await new Argon2id().verify(user.password, password) : false; if (!user || !validPassword) { diff --git a/src/routes/(auth)/register/+page.server.ts b/src/routes/(auth)/register/+page.server.ts index 5e82fcf..885622c 100644 --- a/src/routes/(auth)/register/+page.server.ts +++ b/src/routes/(auth)/register/+page.server.ts @@ -12,9 +12,9 @@ export const actions = { const data = Object.fromEntries(formData) as Record; const result = loginSchema.safeParse(data); - if (!result.success) { return fail(400, { + success: false, message: 'Validation failed', errors: result.error.flatten().fieldErrors, data: { email: data.email } @@ -29,8 +29,11 @@ export const actions = { if (existingUser) { return fail(400, { + success: false, message: 'Email already registered', - errors: { email: ['Email already in use'] }, + errors: { + email: ['Email already in use'] + }, data: { email } }); } @@ -63,8 +66,11 @@ export const actions = { } return fail(500, { + success: false, message: 'An error occurred during registration', - errors: { server: ['Internal server error'] } + errors: { + server: ['Internal server error'] + } }); } } diff --git a/src/routes/(auth)/reset-password/+page.server.ts b/src/routes/(auth)/reset-password/+page.server.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/routes/(auth)/reset-password/+page.svelte b/src/routes/(auth)/reset-password/+page.svelte new file mode 100644 index 0000000..e69de29