From a4e126fa8014fe0dfa46d09aa492c7e0016a6b19 Mon Sep 17 00:00:00 2001 From: sourabh-josh Date: Sat, 28 Sep 2024 19:18:41 +0530 Subject: [PATCH] feat: email passwd auth --- app/migrations/0003_round_wasp.sql | 27 + app/migrations/meta/0003_snapshot.json | 197 ++++ app/migrations/meta/_journal.json | 7 + app/next.config.mjs | 6 +- app/package-lock.json | 915 +++++++++++++++++- app/package.json | 3 + app/src/Validators/register.ts | 2 +- app/src/app/api/register/route.ts | 48 - app/src/app/api/signin/route.ts | 52 + app/src/app/api/signup/route.ts | 70 ++ app/src/app/api/transcribe/save/route.ts | 4 +- app/src/app/favicon.ico | Bin 25931 -> 4286 bytes app/src/app/layout.tsx | 8 - app/src/app/new/page.tsx | 10 +- app/src/app/register/page.tsx | 4 +- app/src/app/signin/page.tsx | 26 + app/src/app/signup/page.tsx | 26 + .../[transcription_id]/page.tsx | 8 +- app/src/app/transcriptions/page.tsx | 8 + app/src/auth.ts | 62 ++ app/src/components/Landing.tsx | 3 +- app/src/components/RecorderCard.tsx | 21 +- .../{RegisterForm.tsx => UserForm.tsx} | 85 +- app/src/db/schema.ts | 23 +- app/src/hooks/useUser.ts | 106 ++ 25 files changed, 1548 insertions(+), 173 deletions(-) create mode 100644 app/migrations/0003_round_wasp.sql create mode 100644 app/migrations/meta/0003_snapshot.json delete mode 100644 app/src/app/api/register/route.ts create mode 100644 app/src/app/api/signin/route.ts create mode 100644 app/src/app/api/signup/route.ts create mode 100644 app/src/app/signin/page.tsx create mode 100644 app/src/app/signup/page.tsx create mode 100644 app/src/auth.ts rename app/src/components/{RegisterForm.tsx => UserForm.tsx} (53%) create mode 100644 app/src/hooks/useUser.ts diff --git a/app/migrations/0003_round_wasp.sql b/app/migrations/0003_round_wasp.sql new file mode 100644 index 0000000..9cc5703 --- /dev/null +++ b/app/migrations/0003_round_wasp.sql @@ -0,0 +1,27 @@ +CREATE TABLE IF NOT EXISTS "session" ( + "id" text PRIMARY KEY NOT NULL, + "user_id" text NOT NULL, + "expires_at" timestamp with time zone NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user" ( + "id" text PRIMARY KEY NOT NULL, + "username" text NOT NULL, + "password_hash" text NOT NULL, + CONSTRAINT "user_username_unique" UNIQUE("username") +); +--> statement-breakpoint +ALTER TABLE "transcriptions" RENAME COLUMN "registrationId" TO "user_id";--> statement-breakpoint +ALTER TABLE "transcriptions" DROP CONSTRAINT "transcriptions_registrationId_registrations_id_fk"; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "session" ADD CONSTRAINT "session_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "transcriptions" ADD CONSTRAINT "transcriptions_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/app/migrations/meta/0003_snapshot.json b/app/migrations/meta/0003_snapshot.json new file mode 100644 index 0000000..62f73d8 --- /dev/null +++ b/app/migrations/meta/0003_snapshot.json @@ -0,0 +1,197 @@ +{ + "id": "2ad32fb7-c2f6-4e9d-a858-c262aea7edc8", + "prevId": "21fe80ad-e01f-4679-8f45-d9b61904fb42", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.registrations": { + "name": "registrations", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "userName": { + "name": "userName", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "userEmail": { + "name": "userEmail", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.transcriptions": { + "name": "transcriptions", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "translation": { + "name": "translation", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "summary": { + "name": "summary", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "default": "now()" + }, + "documentUrl": { + "name": "documentUrl", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "documentName": { + "name": "documentName", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "transcriptions_user_id_user_id_fk": { + "name": "transcriptions_user_id_user_id_fk", + "tableFrom": "transcriptions", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "password_hash": { + "name": "password_hash", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + } + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/app/migrations/meta/_journal.json b/app/migrations/meta/_journal.json index e7a4d30..a9f6490 100644 --- a/app/migrations/meta/_journal.json +++ b/app/migrations/meta/_journal.json @@ -22,6 +22,13 @@ "when": 1726167459613, "tag": "0002_youthful_justice", "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1727517788789, + "tag": "0003_round_wasp", + "breakpoints": true } ] } \ No newline at end of file diff --git a/app/next.config.mjs b/app/next.config.mjs index 4678774..9ede725 100644 --- a/app/next.config.mjs +++ b/app/next.config.mjs @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {}; +const nextConfig = { + experimental: { + serverComponentsExternalPackages: ['@node-rs/argon2'] + } +}; export default nextConfig; diff --git a/app/package-lock.json b/app/package-lock.json index 2e3c89b..34ccc6d 100644 --- a/app/package-lock.json +++ b/app/package-lock.json @@ -9,7 +9,9 @@ "version": "0.1.0", "dependencies": { "@hookform/resolvers": "^3.9.0", + "@lucia-auth/adapter-drizzle": "^1.1.0", "@neondatabase/serverless": "^0.9.4", + "@node-rs/argon2": "^1.8.3", "@radix-ui/react-dropdown-menu": "^2.1.1", "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", @@ -26,6 +28,7 @@ "dotenv": "^16.4.5", "drizzle-orm": "^0.33.0", "framer-motion": "^11.3.31", + "lucia": "^3.2.0", "lucide-react": "^0.437.0", "next": "14.2.7", "next-themes": "^0.3.0", @@ -81,6 +84,33 @@ "effect": "^3.4.5" } }, + "node_modules/@emnapi/core": { + "version": "0.45.0", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-0.45.0.tgz", + "integrity": "sha512-DPWjcUDQkCeEM4VnljEOEcXdAD7pp8zSZsgOujk/LGIwCXWbXJngin+MO4zbH429lzeC3WbYLGjE2MaUOwzpyw==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/runtime": { + "version": "0.45.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-0.45.0.tgz", + "integrity": "sha512-Txumi3td7J4A/xTTwlssKieHKTGl3j4A1tglBx72auZ49YK7ePY6XZricgIg9mnZT4xPfA+UPCUdnhRuEFDL+w==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@emnapi/wasi-threads": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@emnapi/wasi-threads/-/wasi-threads-1.0.1.tgz", + "integrity": "sha512-iIBu7mwkq4UQGeMEM8bLwNK962nXdhodeScX4slfQnRhEMMzvYivHhutCIk8uojvmASXXPC2WNEjwxFWk72Oqw==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@esbuild-kit/core-utils": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/@esbuild-kit/core-utils/-/core-utils-3.3.2.tgz", @@ -1083,6 +1113,54 @@ "@jridgewell/sourcemap-codec": "^1.4.14" } }, + "node_modules/@lucia-auth/adapter-drizzle": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/@lucia-auth/adapter-drizzle/-/adapter-drizzle-1.1.0.tgz", + "integrity": "sha512-iCTnZWvfI5lLZOdUHZYiXA1jaspIFEeo2extLxQ3DjP3uOVys7IPwBi7zezLIRu9dhro4H4Kji+7gSYyjcef2A==", + "peerDependencies": { + "drizzle-orm": ">= 0.29 <1", + "lucia": "3.x" + } + }, + "node_modules/@napi-rs/wasm-runtime": { + "version": "0.2.4", + "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-0.2.4.tgz", + "integrity": "sha512-9zESzOO5aDByvhIAsOy9TbpZ0Ur2AJbUI7UT73kcUTS2mxAMHOBaa1st/jAymNoCtvrit99kkzT1FZuXVcgfIQ==", + "optional": true, + "dependencies": { + "@emnapi/core": "^1.1.0", + "@emnapi/runtime": "^1.1.0", + "@tybys/wasm-util": "^0.9.0" + } + }, + "node_modules/@napi-rs/wasm-runtime/node_modules/@emnapi/core": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/core/-/core-1.2.0.tgz", + "integrity": "sha512-E7Vgw78I93we4ZWdYCb4DGAwRROGkMIXk7/y87UmANR+J6qsWusmC3gLt0H+O0KOt5e6O38U8oJamgbudrES/w==", + "optional": true, + "dependencies": { + "@emnapi/wasi-threads": "1.0.1", + "tslib": "^2.4.0" + } + }, + "node_modules/@napi-rs/wasm-runtime/node_modules/@emnapi/runtime": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/@emnapi/runtime/-/runtime-1.2.0.tgz", + "integrity": "sha512-bV21/9LQmcQeCPEg3BDFtvwL6cwiTMksYNWQQ4KOxCZikEGalWtenoZ0wCiukJINlGCIi2KXx01g4FoH/LxpzQ==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, + "node_modules/@napi-rs/wasm-runtime/node_modules/@tybys/wasm-util": { + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.9.0.tgz", + "integrity": "sha512-6+7nlbMVX/PVDCwaIQ8nTOPveOcFLSt8GcXdx8hD0bt39uWxYT88uXzqTd4fTvqta7oeUJqudepapKNt2DYJFw==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@neondatabase/serverless": { "version": "0.9.4", "resolved": "https://registry.npmjs.org/@neondatabase/serverless/-/serverless-0.9.4.tgz", @@ -1105,10 +1183,437 @@ "glob": "10.3.10" } }, - "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.7.tgz", - "integrity": "sha512-UhZGcOyI9LE/tZL3h9rs/2wMZaaJKwnpAyegUVDGZqwsla6hMfeSj9ssBWQS9yA4UXun3pPhrFLVnw5KXZs3vw==", + "node_modules/@next/swc-darwin-arm64": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.7.tgz", + "integrity": "sha512-UhZGcOyI9LE/tZL3h9rs/2wMZaaJKwnpAyegUVDGZqwsla6hMfeSj9ssBWQS9yA4UXun3pPhrFLVnw5KXZs3vw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-darwin-x64": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.7.tgz", + "integrity": "sha512-ys2cUgZYRc+CbyDeLAaAdZgS7N1Kpyy+wo0b/gAj+SeOeaj0Lw/q+G1hp+DuDiDAVyxLBCJXEY/AkhDmtihUTA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-gnu": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.7.tgz", + "integrity": "sha512-2xoWtE13sUJ3qrC1lwE/HjbDPm+kBQYFkkiVECJWctRASAHQ+NwjMzgrfqqMYHfMxFb5Wws3w9PqzZJqKFdWcQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-arm64-musl": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.7.tgz", + "integrity": "sha512-+zJ1gJdl35BSAGpkCbfyiY6iRTaPrt3KTl4SF/B1NyELkqqnrNX6cp4IjjjxKpd64/7enI0kf6b9O1Uf3cL0pw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-gnu": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.7.tgz", + "integrity": "sha512-m6EBqrskeMUzykBrv0fDX/28lWIBGhMzOYaStp0ihkjzIYJiKUOzVYD1gULHc8XDf5EMSqoH/0/TRAgXqpQwmw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-linux-x64-musl": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.7.tgz", + "integrity": "sha512-gUu0viOMvMlzFRz1r1eQ7Ql4OE+hPOmA7smfZAhn8vC4+0swMZaZxa9CSIozTYavi+bJNDZ3tgiSdMjmMzRJlQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-arm64-msvc": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.7.tgz", + "integrity": "sha512-PGbONHIVIuzWlYmLvuFKcj+8jXnLbx4WrlESYlVnEzDsa3+Q2hI1YHoXaSmbq0k4ZwZ7J6sWNV4UZfx1OeOlbQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-ia32-msvc": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.7.tgz", + "integrity": "sha512-BiSY5umlx9ed5RQDoHcdbuKTUkuFORDqzYKPHlLeS+STUWQKWziVOn3Ic41LuTBvqE0TRJPKpio9GSIblNR+0w==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@next/swc-win32-x64-msvc": { + "version": "14.2.7", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.7.tgz", + "integrity": "sha512-pxsI23gKWRt/SPHFkDEsP+w+Nd7gK37Hpv0ngc5HpWy2e7cKx9zR/+Q2ptAUqICNTecAaGWvmhway7pj/JLEWA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2/-/argon2-1.8.3.tgz", + "integrity": "sha512-sf/QAEI59hsMEEE2J8vO4hKrXrv4Oplte3KI2N4MhMDYpytH0drkVfErmHBfWFZxxIEK03fX1WsBNswS2nIZKg==", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@node-rs/argon2-android-arm-eabi": "1.8.3", + "@node-rs/argon2-android-arm64": "1.8.3", + "@node-rs/argon2-darwin-arm64": "1.8.3", + "@node-rs/argon2-darwin-x64": "1.8.3", + "@node-rs/argon2-freebsd-x64": "1.8.3", + "@node-rs/argon2-linux-arm-gnueabihf": "1.8.3", + "@node-rs/argon2-linux-arm64-gnu": "1.8.3", + "@node-rs/argon2-linux-arm64-musl": "1.8.3", + "@node-rs/argon2-linux-x64-gnu": "1.8.3", + "@node-rs/argon2-linux-x64-musl": "1.8.3", + "@node-rs/argon2-wasm32-wasi": "1.8.3", + "@node-rs/argon2-win32-arm64-msvc": "1.8.3", + "@node-rs/argon2-win32-ia32-msvc": "1.8.3", + "@node-rs/argon2-win32-x64-msvc": "1.8.3" + } + }, + "node_modules/@node-rs/argon2-android-arm-eabi": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-android-arm-eabi/-/argon2-android-arm-eabi-1.8.3.tgz", + "integrity": "sha512-JFZPlNM0A8Og+Tncb8UZsQrhEMlbHBXPsT3hRoKImzVmTmq28Os0ucFWow0AACp2coLHBSydXH3Dh0lZup3rWw==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-android-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-android-arm64/-/argon2-android-arm64-1.8.3.tgz", + "integrity": "sha512-zaf8P3T92caeW2xnMA7P1QvRA4pIt/04oilYP44XlTCtMye//vwXDMeK53sl7dvYiJKnzAWDRx41k8vZvpZazg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-darwin-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-darwin-arm64/-/argon2-darwin-arm64-1.8.3.tgz", + "integrity": "sha512-DV/IbmLGdNXBtXb5o2UI5ba6kvqXqPAJgmMOTUCuHeBSp992GlLHdfU4rzGu0dNrxudBnunNZv+crd0YdEQSUA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-darwin-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-darwin-x64/-/argon2-darwin-x64-1.8.3.tgz", + "integrity": "sha512-YMjmBGFZhLfYjfQ2gll9A+BZu/zAMV7lWZIbKxb7ZgEofILQwuGmExjDtY3Jplido/6leCEdpmlk2oIsME00LA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-freebsd-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-freebsd-x64/-/argon2-freebsd-x64-1.8.3.tgz", + "integrity": "sha512-Hq3Rj5Yb2RolTG/luRPnv+XiGCbi5nAK25Pc8ou/tVapwX+iktEm/NXbxc5zsMxraYVkCvfdwBjweC5O+KqCGw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-linux-arm-gnueabihf": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm-gnueabihf/-/argon2-linux-arm-gnueabihf-1.8.3.tgz", + "integrity": "sha512-x49l8RgzKoG0/V0IXa5rrEl1TcJEc936ctlYFvqcunSOyowZ6kiWtrp1qrbOR8gbaNILl11KTF52vF6+h8UlEQ==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-linux-arm64-gnu": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm64-gnu/-/argon2-linux-arm64-gnu-1.8.3.tgz", + "integrity": "sha512-gJesam/qA63reGkb9qJ2TjFSLBtY41zQh2oei7nfnYsmVQPuHHWItJxEa1Bm21SPW53gZex4jFJbDIgj0+PxIw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-linux-arm64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm64-musl/-/argon2-linux-arm64-musl-1.8.3.tgz", + "integrity": "sha512-7O6kQdSKzB4Tjx/EBa8zKIxnmLkQE8VdJgPm6Ksrpn+ueo0mx2xf76fIDnbbTCtm3UbB+y+FkTo2wLA7tOqIKg==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-linux-x64-gnu": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-x64-gnu/-/argon2-linux-x64-gnu-1.8.3.tgz", + "integrity": "sha512-OBH+EFG7BGjFyldaao2H2gSCLmjtrrwf420B1L+lFn7JLW9UAjsIPFKAcWsYwPa/PwYzIge9Y7SGcpqlsSEX0w==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-linux-x64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-x64-musl/-/argon2-linux-x64-musl-1.8.3.tgz", + "integrity": "sha512-bDbMuyekIxZaN7NaX+gHVkOyABB8bcMEJYeRPW1vCXKHj3brJns1wiUFSxqeUXreupifNVJlQfPt1Y5B/vFXgQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-wasm32-wasi": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-wasm32-wasi/-/argon2-wasm32-wasi-1.8.3.tgz", + "integrity": "sha512-NBf2cMCDbNKMzp13Pog8ZPmI0M9U4Ak5b95EUjkp17kdKZFds12dwW67EMnj7Zy+pRqby2QLECaWebDYfNENTg==", + "cpu": [ + "wasm32" + ], + "optional": true, + "dependencies": { + "@napi-rs/wasm-runtime": "^0.2.3" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@node-rs/argon2-win32-arm64-msvc": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-arm64-msvc/-/argon2-win32-arm64-msvc-1.8.3.tgz", + "integrity": "sha512-AHpPo7UbdW5WWjwreVpgFSY0o1RY4A7cUFaqDXZB2OqEuyrhMxBdZct9PX7PQKI18D85pLsODnR+gvVuTwJ6rQ==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-win32-ia32-msvc": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-ia32-msvc/-/argon2-win32-ia32-msvc-1.8.3.tgz", + "integrity": "sha512-bqzn2rcQkEwCINefhm69ttBVVkgHJb/V03DdBKsPFtiX6H47axXKz62d1imi26zFXhOEYxhKbu3js03GobJOLw==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/argon2-win32-x64-msvc": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-x64-msvc/-/argon2-win32-x64-msvc-1.8.3.tgz", + "integrity": "sha512-ILlrRThdbp5xNR5gwYM2ic1n/vG5rJ8dQZ+YMRqksl+lnTJ/6FDe5BOyIhiPtiDwlCiCtUA+1NxpDB9KlUCAIA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/bcrypt": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt/-/bcrypt-1.9.0.tgz", + "integrity": "sha512-u2OlIxW264bFUfvbFqDz9HZKFjwe8FHFtn7T/U8mYjPZ7DWYpbUB+/dkW/QgYfMSfR0ejkyuWaBBe0coW7/7ig==", + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "optionalDependencies": { + "@node-rs/bcrypt-android-arm-eabi": "1.9.0", + "@node-rs/bcrypt-android-arm64": "1.9.0", + "@node-rs/bcrypt-darwin-arm64": "1.9.0", + "@node-rs/bcrypt-darwin-x64": "1.9.0", + "@node-rs/bcrypt-freebsd-x64": "1.9.0", + "@node-rs/bcrypt-linux-arm-gnueabihf": "1.9.0", + "@node-rs/bcrypt-linux-arm64-gnu": "1.9.0", + "@node-rs/bcrypt-linux-arm64-musl": "1.9.0", + "@node-rs/bcrypt-linux-x64-gnu": "1.9.0", + "@node-rs/bcrypt-linux-x64-musl": "1.9.0", + "@node-rs/bcrypt-wasm32-wasi": "1.9.0", + "@node-rs/bcrypt-win32-arm64-msvc": "1.9.0", + "@node-rs/bcrypt-win32-ia32-msvc": "1.9.0", + "@node-rs/bcrypt-win32-x64-msvc": "1.9.0" + } + }, + "node_modules/@node-rs/bcrypt-android-arm-eabi": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-android-arm-eabi/-/bcrypt-android-arm-eabi-1.9.0.tgz", + "integrity": "sha512-nOCFISGtnodGHNiLrG0WYLWr81qQzZKYfmwHc7muUeq+KY0sQXyHOwZk9OuNQAWv/lnntmtbwkwT0QNEmOyLvA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/bcrypt-android-arm64": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-android-arm64/-/bcrypt-android-arm64-1.9.0.tgz", + "integrity": "sha512-+ZrIAtigVmjYkqZQTThHVlz0+TG6D+GDHWhVKvR2DifjtqJ0i+mb9gjo++hN+fWEQdWNGxKCiBBjwgT4EcXd6A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/bcrypt-darwin-arm64": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-darwin-arm64/-/bcrypt-darwin-arm64-1.9.0.tgz", + "integrity": "sha512-CQiS+F9Pa0XozvkXR1g7uXE9QvBOPOplDg0iCCPRYTN9PqA5qYxhwe48G3o+v2UeQceNRrbnEtWuANm7JRqIhw==", "cpu": [ "arm64" ], @@ -1120,10 +1625,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-darwin-x64": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.7.tgz", - "integrity": "sha512-ys2cUgZYRc+CbyDeLAaAdZgS7N1Kpyy+wo0b/gAj+SeOeaj0Lw/q+G1hp+DuDiDAVyxLBCJXEY/AkhDmtihUTA==", + "node_modules/@node-rs/bcrypt-darwin-x64": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-darwin-x64/-/bcrypt-darwin-x64-1.9.0.tgz", + "integrity": "sha512-4pTKGawYd7sNEjdJ7R/R67uwQH1VvwPZ0SSUMmeNHbxD5QlwAPXdDH11q22uzVXsvNFZ6nGQBg8No5OUGpx6Ug==", "cpu": [ "x64" ], @@ -1135,10 +1640,40 @@ "node": ">= 10" } }, - "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.7.tgz", - "integrity": "sha512-2xoWtE13sUJ3qrC1lwE/HjbDPm+kBQYFkkiVECJWctRASAHQ+NwjMzgrfqqMYHfMxFb5Wws3w9PqzZJqKFdWcQ==", + "node_modules/@node-rs/bcrypt-freebsd-x64": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-freebsd-x64/-/bcrypt-freebsd-x64-1.9.0.tgz", + "integrity": "sha512-UmWzySX4BJhT/B8xmTru6iFif3h0Rpx3TqxRLCcbgmH43r7k5/9QuhpiyzpvKGpKHJCFNm4F3rC2wghvw5FCIg==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/bcrypt-linux-arm-gnueabihf": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-linux-arm-gnueabihf/-/bcrypt-linux-arm-gnueabihf-1.9.0.tgz", + "integrity": "sha512-8qoX4PgBND2cVwsbajoAWo3NwdfJPEXgpCsZQZURz42oMjbGyhhSYbovBCskGU3EBLoC8RA2B1jFWooeYVn5BA==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/@node-rs/bcrypt-linux-arm64-gnu": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-linux-arm64-gnu/-/bcrypt-linux-arm64-gnu-1.9.0.tgz", + "integrity": "sha512-TuAC6kx0SbcIA4mSEWPi+OCcDjTQUMl213v5gMNlttF+D4ieIZx6pPDGTaMO6M2PDHTeCG0CBzZl0Lu+9b0c7Q==", "cpu": [ "arm64" ], @@ -1150,10 +1685,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.7.tgz", - "integrity": "sha512-+zJ1gJdl35BSAGpkCbfyiY6iRTaPrt3KTl4SF/B1NyELkqqnrNX6cp4IjjjxKpd64/7enI0kf6b9O1Uf3cL0pw==", + "node_modules/@node-rs/bcrypt-linux-arm64-musl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-linux-arm64-musl/-/bcrypt-linux-arm64-musl-1.9.0.tgz", + "integrity": "sha512-/sIvKDABOI8QOEnLD7hIj02BVaNOuCIWBKvxcJOt8+TuwJ6zmY1UI5kSv9d99WbiHjTp97wtAUbZQwauU4b9ew==", "cpu": [ "arm64" ], @@ -1165,10 +1700,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.7.tgz", - "integrity": "sha512-m6EBqrskeMUzykBrv0fDX/28lWIBGhMzOYaStp0ihkjzIYJiKUOzVYD1gULHc8XDf5EMSqoH/0/TRAgXqpQwmw==", + "node_modules/@node-rs/bcrypt-linux-x64-gnu": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-linux-x64-gnu/-/bcrypt-linux-x64-gnu-1.9.0.tgz", + "integrity": "sha512-DyyhDHDsLBsCKz1tZ1hLvUZSc1DK0FU0v52jK6IBQxrj24WscSU9zZe7ie/V9kdmA4Ep57BfpWX8Dsa2JxGdgQ==", "cpu": [ "x64" ], @@ -1180,10 +1715,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.7.tgz", - "integrity": "sha512-gUu0viOMvMlzFRz1r1eQ7Ql4OE+hPOmA7smfZAhn8vC4+0swMZaZxa9CSIozTYavi+bJNDZ3tgiSdMjmMzRJlQ==", + "node_modules/@node-rs/bcrypt-linux-x64-musl": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-linux-x64-musl/-/bcrypt-linux-x64-musl-1.9.0.tgz", + "integrity": "sha512-duIiuqQ+Lew8ASSAYm6ZRqcmfBGWwsi81XLUwz86a2HR7Qv6V4yc3ZAUQovAikhjCsIqe8C11JlAZSK6+PlXYg==", "cpu": [ "x64" ], @@ -1195,10 +1730,28 @@ "node": ">= 10" } }, - "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.7.tgz", - "integrity": "sha512-PGbONHIVIuzWlYmLvuFKcj+8jXnLbx4WrlESYlVnEzDsa3+Q2hI1YHoXaSmbq0k4ZwZ7J6sWNV4UZfx1OeOlbQ==", + "node_modules/@node-rs/bcrypt-wasm32-wasi": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-wasm32-wasi/-/bcrypt-wasm32-wasi-1.9.0.tgz", + "integrity": "sha512-ylaGmn9Wjwv/D5lxtawttx3H6Uu2WTTR7lWlRHGT6Ga/MB1Vj4OjSGUW8G8zIVnKuXpGbZ92pgHlt4HUpSLctw==", + "cpu": [ + "wasm32" + ], + "optional": true, + "dependencies": { + "@emnapi/core": "^0.45.0", + "@emnapi/runtime": "^0.45.0", + "@tybys/wasm-util": "^0.8.1", + "memfs-browser": "^3.4.13000" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/@node-rs/bcrypt-win32-arm64-msvc": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-win32-arm64-msvc/-/bcrypt-win32-arm64-msvc-1.9.0.tgz", + "integrity": "sha512-2h86gF7QFyEzODuDFml/Dp1MSJoZjxJ4yyT2Erf4NkwsiA5MqowUhUsorRwZhX6+2CtlGa7orbwi13AKMsYndw==", "cpu": [ "arm64" ], @@ -1210,10 +1763,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.7.tgz", - "integrity": "sha512-BiSY5umlx9ed5RQDoHcdbuKTUkuFORDqzYKPHlLeS+STUWQKWziVOn3Ic41LuTBvqE0TRJPKpio9GSIblNR+0w==", + "node_modules/@node-rs/bcrypt-win32-ia32-msvc": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-win32-ia32-msvc/-/bcrypt-win32-ia32-msvc-1.9.0.tgz", + "integrity": "sha512-kqxalCvhs4FkN0+gWWfa4Bdy2NQAkfiqq/CEf6mNXC13RSV673Ev9V8sRlQyNpCHCNkeXfOT9pgoBdJmMs9muA==", "cpu": [ "ia32" ], @@ -1225,10 +1778,10 @@ "node": ">= 10" } }, - "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.7", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.7.tgz", - "integrity": "sha512-pxsI23gKWRt/SPHFkDEsP+w+Nd7gK37Hpv0ngc5HpWy2e7cKx9zR/+Q2ptAUqICNTecAaGWvmhway7pj/JLEWA==", + "node_modules/@node-rs/bcrypt-win32-x64-msvc": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/@node-rs/bcrypt-win32-x64-msvc/-/bcrypt-win32-x64-msvc-1.9.0.tgz", + "integrity": "sha512-2y0Tuo6ZAT2Cz8V7DHulSlv1Bip3zbzeXyeur+uR25IRNYXKvI/P99Zl85Fbuu/zzYAZRLLlGTRe6/9IHofe/w==", "cpu": [ "x64" ], @@ -1959,6 +2512,15 @@ "react": "^18 || ^19" } }, + "node_modules/@tybys/wasm-util": { + "version": "0.8.3", + "resolved": "https://registry.npmjs.org/@tybys/wasm-util/-/wasm-util-0.8.3.tgz", + "integrity": "sha512-Z96T/L6dUFFxgFJ+pQtkPpne9q7i6kIPYCFnQBHSgSPV9idTsKfIhCss0h5iM9irweZCatkrdeP8yi5uM1eX6Q==", + "optional": true, + "dependencies": { + "tslib": "^2.4.0" + } + }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -4089,6 +4651,12 @@ } } }, + "node_modules/fs-monkey": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/fs-monkey/-/fs-monkey-1.0.6.tgz", + "integrity": "sha512-b1FMfwetIKymC0eioW7mTywihSQE4oLzQn1dB6rZB5fx/3NpNEdAWeCSMB+60/AeT0TCXsxzAlcYVEFCTAksWg==", + "optional": true + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -5089,6 +5657,14 @@ "integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==", "dev": true }, + "node_modules/lucia": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/lucia/-/lucia-3.2.0.tgz", + "integrity": "sha512-eXMxXwk6hqtjRTj4W/x3EnTUtAztLPm0p2N2TEBMDEbakDLXiYnDQ9z/qahjPdPdhPguQc+vwO0/88zIWxlpuw==", + "dependencies": { + "oslo": "1.2.0" + } + }, "node_modules/lucide-react": { "version": "0.437.0", "resolved": "https://registry.npmjs.org/lucide-react/-/lucide-react-0.437.0.tgz", @@ -5097,6 +5673,27 @@ "react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0-rc" } }, + "node_modules/memfs": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/memfs/-/memfs-3.5.3.tgz", + "integrity": "sha512-UERzLsxzllchadvbPs5aolHh65ISpKpM+ccLbOJ8/vvpBKmAWf+la7dXFy7Mr0ySHbdHrFv5kGFCUHHe6GFEmw==", + "optional": true, + "dependencies": { + "fs-monkey": "^1.0.4" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/memfs-browser": { + "version": "3.5.10302", + "resolved": "https://registry.npmjs.org/memfs-browser/-/memfs-browser-3.5.10302.tgz", + "integrity": "sha512-JJTc/nh3ig05O0gBBGZjTCPOyydaTxNF0uHYBrcc1gHNnO+KIHIvo0Y1FKCJsaei6FCl8C6xfQomXqu+cuzkIw==", + "optional": true, + "dependencies": { + "memfs": "3.5.3" + } + }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/merge2/-/merge2-1.4.1.tgz", @@ -5468,6 +6065,252 @@ "node": ">= 0.8.0" } }, + "node_modules/oslo": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/oslo/-/oslo-1.2.0.tgz", + "integrity": "sha512-OoFX6rDsNcOQVAD2gQD/z03u4vEjWZLzJtwkmgfRF+KpQUXwdgEXErD7zNhyowmHwHefP+PM9Pw13pgpHMRlzw==", + "dependencies": { + "@node-rs/argon2": "1.7.0", + "@node-rs/bcrypt": "1.9.0" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2/-/argon2-1.7.0.tgz", + "integrity": "sha512-zfULc+/tmcWcxn+nHkbyY8vP3+MpEqKORbszt4UkpqZgBgDAAIYvuDN/zukfTgdmo6tmJKKVfzigZOPk4LlIog==", + "engines": { + "node": ">= 10" + }, + "optionalDependencies": { + "@node-rs/argon2-android-arm-eabi": "1.7.0", + "@node-rs/argon2-android-arm64": "1.7.0", + "@node-rs/argon2-darwin-arm64": "1.7.0", + "@node-rs/argon2-darwin-x64": "1.7.0", + "@node-rs/argon2-freebsd-x64": "1.7.0", + "@node-rs/argon2-linux-arm-gnueabihf": "1.7.0", + "@node-rs/argon2-linux-arm64-gnu": "1.7.0", + "@node-rs/argon2-linux-arm64-musl": "1.7.0", + "@node-rs/argon2-linux-x64-gnu": "1.7.0", + "@node-rs/argon2-linux-x64-musl": "1.7.0", + "@node-rs/argon2-wasm32-wasi": "1.7.0", + "@node-rs/argon2-win32-arm64-msvc": "1.7.0", + "@node-rs/argon2-win32-ia32-msvc": "1.7.0", + "@node-rs/argon2-win32-x64-msvc": "1.7.0" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-android-arm-eabi": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-android-arm-eabi/-/argon2-android-arm-eabi-1.7.0.tgz", + "integrity": "sha512-udDqkr5P9E+wYX1SZwAVPdyfYvaF4ry9Tm+R9LkfSHbzWH0uhU6zjIwNRp7m+n4gx691rk+lqqDAIP8RLKwbhg==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-android-arm64": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-android-arm64/-/argon2-android-arm64-1.7.0.tgz", + "integrity": "sha512-s9j/G30xKUx8WU50WIhF0fIl1EdhBGq0RQ06lEhZ0Gi0ap8lhqbE2Bn5h3/G2D1k0Dx+yjeVVNmt/xOQIRG38A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-darwin-arm64": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-darwin-arm64/-/argon2-darwin-arm64-1.7.0.tgz", + "integrity": "sha512-ZIz4L6HGOB9U1kW23g+m7anGNuTZ0RuTw0vNp3o+2DWpb8u8rODq6A8tH4JRL79S+Co/Nq608m9uackN2pe0Rw==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-darwin-x64": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-darwin-x64/-/argon2-darwin-x64-1.7.0.tgz", + "integrity": "sha512-5oi/pxqVhODW/pj1+3zElMTn/YukQeywPHHYDbcAW3KsojFjKySfhcJMd1DjKTc+CHQI+4lOxZzSUzK7mI14Hw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-freebsd-x64": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-freebsd-x64/-/argon2-freebsd-x64-1.7.0.tgz", + "integrity": "sha512-Ify08683hA4QVXYoIm5SUWOY5DPIT/CMB0CQT+IdxQAg/F+qp342+lUkeAtD5bvStQuCx/dFO3bnnzoe2clMhA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "freebsd" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-linux-arm-gnueabihf": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm-gnueabihf/-/argon2-linux-arm-gnueabihf-1.7.0.tgz", + "integrity": "sha512-7DjDZ1h5AUHAtRNjD19RnQatbhL+uuxBASuuXIBu4/w6Dx8n7YPxwTP4MXfsvuRgKuMWiOb/Ub/HJ3kXVCXRkg==", + "cpu": [ + "arm" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-linux-arm64-gnu": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm64-gnu/-/argon2-linux-arm64-gnu-1.7.0.tgz", + "integrity": "sha512-nJDoMP4Y3YcqGswE4DvP080w6O24RmnFEDnL0emdI8Nou17kNYBzP2546Nasx9GCyLzRcYQwZOUjrtUuQ+od2g==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-linux-arm64-musl": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-arm64-musl/-/argon2-linux-arm64-musl-1.7.0.tgz", + "integrity": "sha512-BKWS8iVconhE3jrb9mj6t1J9vwUqQPpzCbUKxfTGJfc+kNL58F1SXHBoe2cDYGnHrFEHTY0YochzXoAfm4Dm/A==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-linux-x64-gnu": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-x64-gnu/-/argon2-linux-x64-gnu-1.7.0.tgz", + "integrity": "sha512-EmgqZOlf4Jurk/szW1iTsVISx25bKksVC5uttJDUloTgsAgIGReCpUUO1R24pBhu9ESJa47iv8NSf3yAfGv6jQ==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-linux-x64-musl": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-linux-x64-musl/-/argon2-linux-x64-musl-1.7.0.tgz", + "integrity": "sha512-/o1efYCYIxjfuoRYyBTi2Iy+1iFfhqHCvvVsnjNSgO1xWiWrX0Rrt/xXW5Zsl7vS2Y+yu8PL8KFWRzZhaVxfKA==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-wasm32-wasi": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-wasm32-wasi/-/argon2-wasm32-wasi-1.7.0.tgz", + "integrity": "sha512-Evmk9VcxqnuwQftfAfYEr6YZYSPLzmKUsbFIMep5nTt9PT4XYRFAERj7wNYp+rOcBenF3X4xoB+LhwcOMTNE5w==", + "cpu": [ + "wasm32" + ], + "optional": true, + "dependencies": { + "@emnapi/core": "^0.45.0", + "@emnapi/runtime": "^0.45.0", + "@tybys/wasm-util": "^0.8.1", + "memfs-browser": "^3.4.13000" + }, + "engines": { + "node": ">=14.0.0" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-win32-arm64-msvc": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-arm64-msvc/-/argon2-win32-arm64-msvc-1.7.0.tgz", + "integrity": "sha512-qgsU7T004COWWpSA0tppDqDxbPLgg8FaU09krIJ7FBl71Sz8SFO40h7fDIjfbTT5w7u6mcaINMQ5bSHu75PCaA==", + "cpu": [ + "arm64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-win32-ia32-msvc": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-ia32-msvc/-/argon2-win32-ia32-msvc-1.7.0.tgz", + "integrity": "sha512-JGafwWYQ/HpZ3XSwP4adQ6W41pRvhcdXvpzIWtKvX+17+xEXAe2nmGWM6s27pVkg1iV2ZtoYLRDkOUoGqZkCcg==", + "cpu": [ + "ia32" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, + "node_modules/oslo/node_modules/@node-rs/argon2-win32-x64-msvc": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/@node-rs/argon2-win32-x64-msvc/-/argon2-win32-x64-msvc-1.7.0.tgz", + "integrity": "sha512-9oq4ShyFakw8AG3mRls0AoCpxBFcimYx7+jvXeAf2OqKNO+mSA6eZ9z7KQeVCi0+SOEUYxMGf5UiGiDb9R6+9Q==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + } + }, "node_modules/p-limit": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz", diff --git a/app/package.json b/app/package.json index 138391a..d92953d 100644 --- a/app/package.json +++ b/app/package.json @@ -10,7 +10,9 @@ }, "dependencies": { "@hookform/resolvers": "^3.9.0", + "@lucia-auth/adapter-drizzle": "^1.1.0", "@neondatabase/serverless": "^0.9.4", + "@node-rs/argon2": "^1.8.3", "@radix-ui/react-dropdown-menu": "^2.1.1", "@radix-ui/react-icons": "^1.3.0", "@radix-ui/react-label": "^2.1.0", @@ -27,6 +29,7 @@ "dotenv": "^16.4.5", "drizzle-orm": "^0.33.0", "framer-motion": "^11.3.31", + "lucia": "^3.2.0", "lucide-react": "^0.437.0", "next": "14.2.7", "next-themes": "^0.3.0", diff --git a/app/src/Validators/register.ts b/app/src/Validators/register.ts index f3364bd..4b38b4a 100644 --- a/app/src/Validators/register.ts +++ b/app/src/Validators/register.ts @@ -1,8 +1,8 @@ import { z } from "zod"; export const registerUserSchema = z.object({ - userName: z.string().min(3).max(32), userEmail: z.string().email(), + password: z.string().min(8).max(16), }); export type RegisterUserRequest = z.infer; diff --git a/app/src/app/api/register/route.ts b/app/src/app/api/register/route.ts deleted file mode 100644 index ce6f4d4..0000000 --- a/app/src/app/api/register/route.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { db } from "@/db"; -import { registrations } from "@/db/schema"; -import { registerUserSchema } from "@/Validators/register"; -import { eq } from "drizzle-orm"; -import { z } from "zod"; - -export async function POST(req: Request) { - try { - const body = await req.json(); - - const { userEmail, userName } = registerUserSchema.parse(body); - - // check if user already exists - const user = await db - .select({ - id: registrations.id, - }) - .from(registrations) - .where(eq(registrations.userEmail, userEmail)); - - if (user.length > 0) - return new Response(JSON.stringify({ userId: user[0].id }), { - status: 200, - }); - - // register user - const response = await db - .insert(registrations) - .values({ - userEmail, - userName, - }) - .returning(); - - if (response) { - return new Response(JSON.stringify({ userId: response[0].id }), { - status: 201, - }); - } - } catch (error) { - console.log(error); - - if (error instanceof z.ZodError) { - return new Response(error.message, { status: 422 }); - } - return new Response("Failed to Register User", { status: 500 }); - } -} diff --git a/app/src/app/api/signin/route.ts b/app/src/app/api/signin/route.ts new file mode 100644 index 0000000..10e5105 --- /dev/null +++ b/app/src/app/api/signin/route.ts @@ -0,0 +1,52 @@ +import { lucia } from "@/auth"; +import { db } from "@/db"; +import { userTable } from "@/db/schema"; +import { registerUserSchema } from "@/Validators/register"; +import { verify } from "@node-rs/argon2"; +import { eq } from "drizzle-orm"; +import { cookies } from "next/headers"; +import { z } from "zod"; + +export async function POST(req: Request) { + try { + const body = await req.json(); + const { password, userEmail } = registerUserSchema.parse(body); + + // check if user exists + const existingUser = await db + .select() + .from(userTable) + .where(eq(userTable.username, userEmail)) + + if (!existingUser[0]) { + return new Response("User not found", { + status: 404, + }) + } + + // login user + const validPassword = await verify(existingUser[0].password_hash, password, { + memoryCost: 19456, + timeCost: 2, + outputLen: 32, + parallelism: 1 + }); + if (!validPassword) { + return new Response("Incorrect username or password", { status: 401 }) + } + + const session = await lucia.createSession(existingUser[0].id, {}); + const sessionCookie = lucia.createSessionCookie(session.id); + cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes); + + return new Response("User Logged In", { status: 200 }); + + } catch (error) { + console.log(error); + + if (error instanceof z.ZodError) { + return new Response(error.message, { status: 422 }); + } + return new Response("Failed to Register User", { status: 500 }); + } +} diff --git a/app/src/app/api/signup/route.ts b/app/src/app/api/signup/route.ts new file mode 100644 index 0000000..e4bdee6 --- /dev/null +++ b/app/src/app/api/signup/route.ts @@ -0,0 +1,70 @@ +import { lucia } from "@/auth"; +import { db } from "@/db"; +import { registrations, userTable } from "@/db/schema"; +import { registerUserSchema } from "@/Validators/register"; +import { hash } from "@node-rs/argon2"; +import { eq } from "drizzle-orm"; +import { generateIdFromEntropySize } from "lucia"; +import { cookies } from "next/headers"; +import { redirect } from "next/navigation"; +import { z } from "zod"; + +export async function POST(req: Request) { + try { + const body = await req.json(); + + const { password, userEmail } = registerUserSchema.parse(body); + + // check if user already exists + const user = await db + .select({ + id: userTable.id, + }) + .from(userTable) + .where(eq(userTable.username, userEmail)); + + if (user.length > 0) + return new Response("User already exists", { + status: 409, + }); + + // register user + + // generate id from hash + const passwordHash = await hash(password, { + // recommended minimum parameters + memoryCost: 19456, + timeCost: 2, + outputLen: 32, + parallelism: 1 + }); + + const userId = generateIdFromEntropySize(10); // 16 characters long + + const response = await db + .insert(userTable) + .values({ + id: userId, + username:userEmail, + password_hash: passwordHash, + }) + .returning(); + + if (response) { + const session = await lucia.createSession(userId, {}); + const sessionCookie = lucia.createSessionCookie(session.id); + cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes); + + return new Response(JSON.stringify({ userId: response[0].id }), { + status: 201, + }); + } + } catch (error) { + console.log(error); + + if (error instanceof z.ZodError) { + return new Response(error.message, { status: 422 }); + } + return new Response("Failed to Register User", { status: 500 }); + } +} diff --git a/app/src/app/api/transcribe/save/route.ts b/app/src/app/api/transcribe/save/route.ts index ed5985c..03e6ab4 100644 --- a/app/src/app/api/transcribe/save/route.ts +++ b/app/src/app/api/transcribe/save/route.ts @@ -6,7 +6,7 @@ export async function POST(req: Request) { const body = await req.json(); const { documentUrl, - registrationId, + userID, documentName, summary, translation, @@ -15,7 +15,7 @@ export async function POST(req: Request) { const response = await db.insert(transcriptions).values({ documentUrl, documentName, - registrationId, + userID, summary, translation, }).returning(); diff --git a/app/src/app/favicon.ico b/app/src/app/favicon.ico index 718d6fea4835ec2d246af9800eddb7ffb276240c..3556c329e6f7272c3096435bacead4da50444980 100644 GIT binary patch literal 4286 zcmcJTO=uKX9KhdZH#xpwu>{*vRs?&?RMVy>B^U9t8nj5V#*DwWvy)`MW@pxQ<>#Bsy!rqB z@4f%N7Zt+CpQTHM{99aHAVf$A5eIIGPeI<#e0Wx^PeL>1Kpz}~+G@ph6DQF%RFlw# zcH(^rk6=Th%ka5*w;Fx$uYtQb%?z4xn;c@*h+Qs5hh{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@ import type { Metadata } from "next"; import "./globals.css"; -import { ThemeProvider } from "@/providers/ThemeProvider"; import { Toaster } from "@/components/ui/sonner"; import TanstackQueryProvider from "@/providers/TanstackQueryProvider"; import { secondaryFont } from "@/fonts"; @@ -20,18 +19,11 @@ export default function RootLayout({ -
{children}
-
diff --git a/app/src/app/new/page.tsx b/app/src/app/new/page.tsx index 8c69326..b7a5cfb 100644 --- a/app/src/app/new/page.tsx +++ b/app/src/app/new/page.tsx @@ -1,19 +1,25 @@ +import { validateRequest } from "@/auth"; import NavigateBack from "@/components/NavigateBack"; import RecorderCard from "@/components/RecorderCard"; import { Metadata } from "next"; +import { redirect } from "next/navigation"; export const metadata: Metadata = { title: "Lingo.ai | New", }; -const page = () => { +const page = async () => { + const { user } = await validateRequest(); + + if (!user) return redirect("/signin"); + return (
- +
); diff --git a/app/src/app/register/page.tsx b/app/src/app/register/page.tsx index f88c27c..eb1ba1d 100644 --- a/app/src/app/register/page.tsx +++ b/app/src/app/register/page.tsx @@ -1,5 +1,5 @@ import NavigateBack from "@/components/NavigateBack"; -import RegisterForm from "@/components/RegisterForm"; +import RegisterForm from "@/components/UserForm"; import { Metadata } from "next"; @@ -14,7 +14,7 @@ const page = async () => {
- + {/* */}
); diff --git a/app/src/app/signin/page.tsx b/app/src/app/signin/page.tsx new file mode 100644 index 0000000..091b983 --- /dev/null +++ b/app/src/app/signin/page.tsx @@ -0,0 +1,26 @@ +import { validateRequest } from "@/auth"; +import NavigateBack from "@/components/NavigateBack"; +import UserForm from "@/components/UserForm"; +import { redirect } from "next/navigation"; + +export const dynamic = "force-dynamic"; +export const fetchCache = "force-no-store"; +export const revalidate = 0; + + +export default async function Page() { + + const { user } = await validateRequest(); + if (user) return redirect("/new"); + + return ( +
+
+ +
+
+ +
+
+ ); +} diff --git a/app/src/app/signup/page.tsx b/app/src/app/signup/page.tsx new file mode 100644 index 0000000..4d046c0 --- /dev/null +++ b/app/src/app/signup/page.tsx @@ -0,0 +1,26 @@ +import { validateRequest } from "@/auth"; +import NavigateBack from "@/components/NavigateBack"; +import UserForm from "@/components/UserForm"; +import { redirect } from "next/navigation"; + +export const dynamic = "force-dynamic"; +export const fetchCache = "force-no-store"; +export const revalidate = 0; + + +export default async function Page() { + + const { user } = await validateRequest(); + if (user) return redirect("/new"); + + return ( +
+
+ +
+
+ +
+
+ ); +} diff --git a/app/src/app/transcriptions/[transcription_id]/page.tsx b/app/src/app/transcriptions/[transcription_id]/page.tsx index bdc3cd4..4284eb0 100644 --- a/app/src/app/transcriptions/[transcription_id]/page.tsx +++ b/app/src/app/transcriptions/[transcription_id]/page.tsx @@ -1,5 +1,6 @@ // transcriptions / [transcription_id] / page.tsx +import { validateRequest } from "@/auth"; import DetailedTranscription from "@/components/DetailedTranscription"; import NavigateBack from "@/components/NavigateBack"; import { db } from "@/db"; @@ -7,6 +8,7 @@ import { transcriptions } from "@/db/schema"; import { eq } from "drizzle-orm"; import { Metadata } from "next"; +import { redirect } from "next/navigation"; export const metadata: Metadata = { title: "Lingo.ai | Transcription", @@ -21,6 +23,10 @@ interface PageProps { const page = async (props: PageProps) => { const { transcription_id } = props.params; + const { user } = await validateRequest(); + + if (!user) return redirect("/signin"); + const transcription = await db .select() .from(transcriptions) @@ -30,7 +36,7 @@ const page = async (props: PageProps) => {
- +
{transcription.length > 0 && ( diff --git a/app/src/app/transcriptions/page.tsx b/app/src/app/transcriptions/page.tsx index 99b53b1..38935d3 100644 --- a/app/src/app/transcriptions/page.tsx +++ b/app/src/app/transcriptions/page.tsx @@ -1,3 +1,4 @@ +import { validateRequest } from "@/auth"; import NavigateBack from "@/components/NavigateBack"; import TranscriptionItem from "@/components/TranscriptionItem"; import { db } from "@/db"; @@ -9,12 +10,19 @@ export const fetchCache = "force-no-store"; export const revalidate = 0; import { Metadata } from "next"; +import { redirect } from "next/navigation"; export const metadata: Metadata = { title: "Lingo.ai | Transcriptions", }; const page = async () => { + + const {user} = await validateRequest(); + + if (!user) return redirect("/signin"); + + const userTranscriptions = await db .select({ id: transcriptions.id, diff --git a/app/src/auth.ts b/app/src/auth.ts new file mode 100644 index 0000000..dce5ae3 --- /dev/null +++ b/app/src/auth.ts @@ -0,0 +1,62 @@ +// src/auth.ts +import { Lucia } from "lucia"; +import { db } from "./db"; +import { DrizzlePostgreSQLAdapter } from "@lucia-auth/adapter-drizzle"; +import { sessionTable, userTable } from "./db/schema"; +import { cookies } from "next/headers"; +import { cache } from "react"; +import type { Session, User } from "lucia"; + +const adapter = new DrizzlePostgreSQLAdapter(db,sessionTable,userTable); + +export const lucia = new Lucia(adapter, { + sessionCookie: { + expires: false, + attributes: { + secure: process.env.NODE_ENV === "production" + } + }, + getUserAttributes: (attributes) => { + return { + // attributes has the type of DatabaseUserAttributes + username: attributes.username + }; + } +}); + +export const validateRequest = cache( + async (): Promise<{ user: User; session: Session } | { user: null; session: null }> => { + const sessionId = cookies().get(lucia.sessionCookieName)?.value ?? null; + if (!sessionId) { + return { + user: null, + session: null + }; + } + + const result = await lucia.validateSession(sessionId); + // next.js throws when you attempt to set cookie when rendering page + try { + if (result.session && result.session.fresh) { + const sessionCookie = lucia.createSessionCookie(result.session.id); + cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes); + } + if (!result.session) { + const sessionCookie = lucia.createBlankSessionCookie(); + cookies().set(sessionCookie.name, sessionCookie.value, sessionCookie.attributes); + } + } catch {} + return result; + } +); + +declare module "lucia" { + interface Register { + Lucia: typeof lucia; + DatabaseUserAttributes: DatabaseUserAttributes; + } +} + +interface DatabaseUserAttributes { + username: string; +} \ No newline at end of file diff --git a/app/src/components/Landing.tsx b/app/src/components/Landing.tsx index 93cbb18..a32fbcc 100644 --- a/app/src/components/Landing.tsx +++ b/app/src/components/Landing.tsx @@ -8,7 +8,6 @@ import { useRouter } from "next/navigation"; import Link from "next/link"; const Landing = () => { - const router = useRouter(); return (
@@ -24,7 +23,7 @@ const Landing = () => { with ease.

{ +interface RecorderCardProps { + userId: string; +} +const RecorderCard = (props:RecorderCardProps) => { + const { userId } = props; + const router = useRouter(); const [file, setFile] = useState(null); const [uploadProgress, setUploadProgress] = useState(0); @@ -33,22 +38,12 @@ const RecorderCard = () => { const [audioURL, setAudioURL] = useState(""); const [recordingTime, setRecordingTime] = useState(0); const [isPlaying, setIsPlaying] = useState(false); - const [user, setUser] = useState(null); const mediaRecorder = useRef(null); const chunks = useRef([]); const audioRef = useRef(null); const timerRef = useRef(null); - useEffect(() => { - const storedUser = localStorage.getItem("user"); - if (!storedUser) { - router.push("/register"); - } else { - setUser(storedUser); - } - }, [router]); - const handleFileChange = (newFiles: File[]) => { if (newFiles.length > 0) { setFile(newFiles[0]); @@ -102,7 +97,7 @@ const RecorderCard = () => { saveTranscribe({ documentUrl: data.documentUrl, documentName: data.documentName, - registrationId: JSON.parse(user!).userId, + userID: userId, summary: res.summary, translation: res.translation, }); @@ -219,7 +214,7 @@ const RecorderCard = () => { return `${minutes}:${seconds < 10 ? "0" : ""}${seconds}`; }; - if (!user) { + if (!userId) { return ; } diff --git a/app/src/components/RegisterForm.tsx b/app/src/components/UserForm.tsx similarity index 53% rename from app/src/components/RegisterForm.tsx rename to app/src/components/UserForm.tsx index 9113c39..80e1060 100644 --- a/app/src/components/RegisterForm.tsx +++ b/app/src/components/UserForm.tsx @@ -15,62 +15,35 @@ import { import { zodResolver } from "@hookform/resolvers/zod"; import { useForm } from "react-hook-form"; import { RegisterUserRequest, registerUserSchema } from "@/Validators/register"; -import { useMutation } from "@tanstack/react-query"; -import axios, { AxiosError } from "axios"; -import { toast } from "sonner"; -import { useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; -const RegisterForm = () => { - const router = useRouter(); - const [isPersistingUser,setIsPersistingUser] = useState(false); +import { useUser } from "@/hooks/useUser"; - useEffect(() => { - if (typeof window !== "undefined" && localStorage.getItem("user")) { - router.push("/new"); - } - }, [router]); +interface UserFormProps { + formType: "signin" | "signup"; +} + +const UserForm = (props: UserFormProps) => { + + const { formType } = props; + + const { disableSubmit, isPending, signupUser, signinUser } = useUser(); const form = useForm({ resolver: zodResolver(registerUserSchema), defaultValues: { - userName: "", + password: "", userEmail: "", }, mode: "all", }); - const { mutate, isPending } = useMutation({ - mutationKey: ["registerUser"], - mutationFn: async (payload: RegisterUserRequest) => { - const response = await axios.post("/api/register", payload); - return response.data; - }, - onSuccess: async (res) => { - if (typeof window !== "undefined") { - localStorage.setItem("user", JSON.stringify(res)); - } - form.reset(); - router.push("/new"); - setIsPersistingUser(false); - }, - onError: (error) => { - if (error instanceof AxiosError) { - if (error.response?.status === 422) { - return toast.error("Failed to Register User", { - description: error.message, - }); - } - } - return toast.error( - "Failed to Register User, please try again in some time", - ); - }, - }); const onSubmit = (data: RegisterUserRequest) => { - setIsPersistingUser(true); - mutate(data); + if (formType === "signup") + signupUser(data) + else + // console.log("Signin User") + signinUser(data) }; return ( @@ -80,17 +53,19 @@ const RegisterForm = () => { className="w-full max-w-sm flex flex-col gap-4 justify-center items-center" >

- Register + { + formType === "signup" ? "Sign Up" : "Sign In" + }

( - Name + Email - + @@ -100,12 +75,12 @@ const RegisterForm = () => {
( - Email + Password - + @@ -113,16 +88,18 @@ const RegisterForm = () => { />
); }; -export default RegisterForm; \ No newline at end of file +export default UserForm; \ No newline at end of file diff --git a/app/src/db/schema.ts b/app/src/db/schema.ts index 92200a3..56e0b11 100644 --- a/app/src/db/schema.ts +++ b/app/src/db/schema.ts @@ -2,9 +2,9 @@ import { timestamp, pgTable, text, uuid } from "drizzle-orm/pg-core"; export const transcriptions = pgTable("transcriptions", { id: uuid("id").primaryKey().defaultRandom(), - registrationId: text("registrationId") - .notNull() - .references(() => registrations.id, { onDelete: "cascade" }), + userID: text("user_id") + .notNull() + .references(() => userTable.id), translation: text("translation").notNull(), summary: text("summary").notNull(), createdAt: timestamp("createdAt", { mode: "date" }).defaultNow(), @@ -21,5 +21,22 @@ export const registrations = pgTable("registrations", { createdAt: timestamp("createdAt", { mode: "date" }).defaultNow(), }); +export const userTable = pgTable("user", { + id: text("id").primaryKey(), + username: text("username").notNull().unique(), + password_hash: text("password_hash").notNull(), +}); + +export const sessionTable = pgTable("session", { + id: text("id").primaryKey(), + userId: text("user_id") + .notNull() + .references(() => userTable.id), + expiresAt: timestamp("expires_at", { + withTimezone: true, + mode: "date" + }).notNull() +}); + export type TranscriptionsPayload = typeof transcriptions.$inferInsert; export type TranscriptionsType = typeof transcriptions.$inferSelect; diff --git a/app/src/hooks/useUser.ts b/app/src/hooks/useUser.ts new file mode 100644 index 0000000..fdae041 --- /dev/null +++ b/app/src/hooks/useUser.ts @@ -0,0 +1,106 @@ +'use client'; + +import { useMutation } from "@tanstack/react-query"; +import axios, { AxiosError } from "axios"; +import { toast } from "sonner"; +import { useRouter } from "next/navigation"; +import { RegisterUserRequest } from "@/Validators/register"; +import { useState } from "react"; + +export const useUser = () => { + + const router = useRouter(); + + const [disableSubmit,setDisableSubmit] = useState(false); + const { mutate:signup, isPending:isSigningUp } = useMutation({ + mutationKey: ["signup-user"], + mutationFn: async (payload: RegisterUserRequest) => { + const response = await axios.post("/api/signup", payload); + return response.data; + }, + onSuccess: async (res) => { + toast.success("User Registered Successfully"); + router.push("/") + }, + onError: (error) => { + if (error instanceof AxiosError) { + if (error.response?.status === 422) { + return toast.error("Failed to Register User", { + description: error.message, + }); + } + else if(error.response?.status === 409){ + return toast.error("User already exists, please sign in", { + action: { + label: "Signin", + onClick: () => router.push("/signin"), + } + }); + } + } + return toast.error( + "Failed to Register User, please try again in some time", + ); + }, + onSettled: () => { + setDisableSubmit(false); + } + }); + + const { mutate:signin, isPending:isSigningIn } = useMutation({ + mutationKey: ["signin-user"], + mutationFn: async (payload: RegisterUserRequest) => { + const response = await axios.post("/api/signin", payload); + return response.data; + }, + onSuccess: async (res) => { + toast.success("User sign in Successfull"); + router.push("/") + }, + onError: (error) => { + if (error instanceof AxiosError) { + if (error.response?.status === 422) { + return toast.error("Failed to sign in User", { + description: error.message, + }); + } + else if(error.response?.status === 404){ + return toast.error("User does not exists", { + action: { + label: "Signup", + onClick: () => router.push("/signup"), + } + }); + } + else if(error.response?.status === 401){ + return toast.error("Incorrect username or password"); + } + } + return toast.error( + "Failed to sign in User, please try again in some time", + ); + }, + onSettled: () => { + setDisableSubmit(false); + } + }); + + const signupUser = (data: RegisterUserRequest) => { + setDisableSubmit(true); + signup(data); + } + + const signinUser = (data: RegisterUserRequest) => { + setDisableSubmit(true); + signin(data); + } + + return { + signupUser, + signinUser, + isPending: isSigningUp || isSigningIn, + disableSubmit + } + +} +