diff --git a/bun.lockb b/bun.lockb
index 4301cd5..85d62b4 100755
Binary files a/bun.lockb and b/bun.lockb differ
diff --git a/package.json b/package.json
index d0c6c09..ea9b4ec 100644
--- a/package.json
+++ b/package.json
@@ -36,6 +36,7 @@
"formsnap": "^0.4.1",
"lucide-svelte": "^0.292.0",
"mode-watcher": "^0.0.7",
+ "nanoid": "^5.0.3",
"postgres": "^3.4.3",
"sveltekit-superforms": "^1.10.1",
"tailwind-merge": "^2.0.0",
diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts
index be6ace8..baaa5ff 100644
--- a/src/routes/(auth)/login/+page.server.ts
+++ b/src/routes/(auth)/login/+page.server.ts
@@ -5,6 +5,7 @@ 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';
export const load = (async () => {
return {
@@ -16,7 +17,6 @@ export const actions: Actions = {
default: async (event) => {
const form = await superValidate(event, formSchema);
- console.log(form);
if (!form.valid) {
return fail(400, {
form,
@@ -34,6 +34,12 @@ export const actions: Actions = {
user && (await Bun.password.verify(form.data.password, user.password));
if (user && matchPassword) {
+ const token = nanoid(32);
+ event.cookies.set('token', token, {
+ httpOnly: true,
+ sameSite: 'strict',
+ path: '/',
+ });
return {
form,
};
diff --git a/src/routes/(auth)/signup/(components)/user-auth-form.svelte b/src/routes/(auth)/signup/(components)/user-auth-form.svelte
index d447b8a..ed665b2 100644
--- a/src/routes/(auth)/signup/(components)/user-auth-form.svelte
+++ b/src/routes/(auth)/signup/(components)/user-auth-form.svelte
@@ -1,62 +1,32 @@
-
+
+
+
+ Email
+
+
+
+
+
+
+ Password
+
+
+
+
+
+
+ Password Confirm
+
+
+
+
+ Sign Up
+
diff --git a/src/routes/(auth)/signup/+page.server.ts b/src/routes/(auth)/signup/+page.server.ts
new file mode 100644
index 0000000..81ed753
--- /dev/null
+++ b/src/routes/(auth)/signup/+page.server.ts
@@ -0,0 +1,71 @@
+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';
+
+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) {
+ await db
+ .insert(userSchema)
+ .values({ email: form.data.email, password: form.data.password });
+ const token = nanoid(32);
+ event.cookies.set('token', token, {
+ httpOnly: true,
+ sameSite: 'strict',
+ path: '/',
+ });
+ return {
+ form,
+ };
+ } else {
+ return fail(400, {
+ form,
+ });
+ }
+ } catch (error) {
+ if (error instanceof SyntaxError) {
+ return fail(400, {
+ form,
+ });
+ } else {
+ console.log(error);
+ return fail(400, {
+ form,
+ });
+ }
+ }
+ },
+};
diff --git a/src/routes/(auth)/signup/+page.svelte b/src/routes/(auth)/signup/+page.svelte
index 6dd0ed4..701d4b3 100644
--- a/src/routes/(auth)/signup/+page.svelte
+++ b/src/routes/(auth)/signup/+page.svelte
@@ -1,6 +1,9 @@
-
+
Already Have An Account? Login{' '}