diff --git a/frontend/src/routes/(auth)/signup/(components)/form.svelte b/frontend/src/routes/(auth)/signup/(components)/form.svelte new file mode 100644 index 0000000..ccaab68 --- /dev/null +++ b/frontend/src/routes/(auth)/signup/(components)/form.svelte @@ -0,0 +1,69 @@ + + +
+
Enter your email below to create your account
+
+Already Have An Account? Login{' '} + class="underline underline-offset-4 hover:text-primary"> Here {' '}
diff --git a/frontend/src/routes/(auth)/signup/schema.ts b/frontend/src/routes/(auth)/signup/schema.ts index 7d2c758..46eb6b0 100644 --- a/frontend/src/routes/(auth)/signup/schema.ts +++ b/frontend/src/routes/(auth)/signup/schema.ts @@ -2,8 +2,16 @@ import { z } from 'zod' export const formSchema = z.object({ email: z.string().email(), - password: z.string().min(8), - password_confirm: z.string().min(8), + password: z + .string() + .min(8, { + message: 'Password must be at least 8 characters long', + }), + password_confirm: z + .string() + .min(8, { + message: 'Password must be at least 8 characters long', + }), }) export type FormSchema = typeof formSchema diff --git a/frontend/src/routes/api/signup/+server.ts b/frontend/src/routes/api/signup/+server.ts deleted file mode 100644 index 066c5cd..0000000 --- a/frontend/src/routes/api/signup/+server.ts +++ /dev/null @@ -1,76 +0,0 @@ -import type { RequestHandler } from './$types' -import { user as userSchema } from '$lib/db/schema' -import { eq } from 'drizzle-orm' -import { userCreateSchema } from '$lib/server/types' -import { db } from '$lib/db' -import { lucia } from '$lib/server/auth' - -export const GET: RequestHandler = async () => { - return new Response() -} - -export const POST: RequestHandler = async (event) => { - const body = await event.request.json() - - const userCreate = userCreateSchema.safeParse(body) - - if (!userCreate.success) { - return new Response( - JSON.stringify({ - success: false, - }), - ) - } - - if (userCreate.data.password !== userCreate.data.password_confirm) { - return new Response( - JSON.stringify({ - success: false, - message: 'password doesnt match', - }), - ) - } - - const users = await db - .select() - .from(userSchema) - .where(eq(userSchema.email, userCreate.data.email)) - - const user = users[0] - - if (!user) { - const hashedPassword = await Bun.password.hash( - userCreate.data.password, - ) - const returnUsers = await db - .insert(userSchema) - .values({ - email: userCreate.data.email, - password: hashedPassword, - }) - .returning() - - const user = returnUsers[0] - - const session = await lucia.createSession(user.id, {}) - const sessionCookie = lucia.createSessionCookie(session.id) - - event.cookies.set(sessionCookie.name, sessionCookie.value, { - ...sessionCookie.attributes, - path: '/', - secure: Bun.env.APP_ENV === 'prod', - }) - - return new Response( - JSON.stringify({ - success: true, - }), - ) - } else { - return new Response( - JSON.stringify({ - success: false, - }), - ) - } -}