From 2a6b63fcba97f87cc4f9eb34825eb1f2a7973f45 Mon Sep 17 00:00:00 2001 From: TZGyn Date: Sat, 6 Jan 2024 15:15:35 +0800 Subject: [PATCH] update signup page --- .../src/routes/(auth)/signup/+page.server.ts | 76 ------------------- .../src/routes/(auth)/signup/+page.svelte | 15 ++-- 2 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 frontend/src/routes/(auth)/signup/+page.server.ts diff --git a/frontend/src/routes/(auth)/signup/+page.server.ts b/frontend/src/routes/(auth)/signup/+page.server.ts deleted file mode 100644 index 2567338..0000000 --- a/frontend/src/routes/(auth)/signup/+page.server.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { PageServerLoad, Actions } from './$types' -import { fail } from '@sveltejs/kit' -import { superValidate } from 'sveltekit-superforms/server' -import { formSchema } from './schema' -import { db } from '$lib/db' -import { user as userSchema } from '$lib/db/schema' -import { eq } from 'drizzle-orm' -import { nanoid } from 'nanoid' -import * as argon2 from 'argon2' - -export const load = (async () => { - return { - form: superValidate(formSchema), - } -}) satisfies PageServerLoad - -export const actions: Actions = { - default: async (event) => { - const form = await superValidate(event, formSchema) - - if (!form.valid) { - return fail(400, { - form, - }) - } - - if (form.data.password !== form.data.password_confirm) { - return fail(400, { - form, - }) - } - - try { - const users = await db - .select() - .from(userSchema) - .where(eq(userSchema.email, form.data.email)) - - const user = users[0] - - if (!user) { - // const hashedPassword = await Bun.password.hash(form.data.password) - const hashedPassword = await argon2.hash(form.data.password) - await db.insert(userSchema).values({ - email: form.data.email, - password: hashedPassword, - }) - const token = nanoid(32) - event.cookies.set('token', token, { - httpOnly: true, - sameSite: 'strict', - path: '/', - }) - return { - form, - } - } else { - return fail(400, { - form, - }) - } - } catch (error) { - console.log(error) - if (error instanceof SyntaxError) { - return fail(400, { - form, - }) - } else { - console.log(error) - return fail(400, { - form, - }) - } - } - }, -} diff --git a/frontend/src/routes/(auth)/signup/+page.svelte b/frontend/src/routes/(auth)/signup/+page.svelte index ecfe027..eb7e01e 100644 --- a/frontend/src/routes/(auth)/signup/+page.svelte +++ b/frontend/src/routes/(auth)/signup/+page.svelte @@ -1,9 +1,6 @@
@@ -25,16 +22,16 @@

Create an account

-

+

Enter your email below to create your account

- -

+ +

Already Have An Account? Login{' '} + class="hover:text-primary underline underline-offset-4"> Here {' '}