Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

add signin auth

Khuram Niazca18b1113bba
diff --git a/next.config.mjs b/next.config.mjs
index 4678774..0a7c9af 100644
--- a/next.config.mjs
+++ b/next.config.mjs
@@ -1,4 +1,5 @@
/** @type {import('next').NextConfig} */
-const nextConfig = {};
+const nextConfig = {
+};
export default nextConfig;
diff --git a/package-lock.json b/package-lock.json
index 8cd980d..703a980 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -20,10 +20,12 @@
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
+ "bcryptjs": "^2.4.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.379.0",
"next": "14.2.3",
+ "next-auth": "^5.0.0-beta.18",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
@@ -33,6 +35,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
+ "@types/bcrypt": "^5.0.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
@@ -55,6 +58,36 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
+ "node_modules/@auth/core": {
+ "version": "0.31.0",
+ "resolved": "https://registry.npmjs.org/@auth/core/-/core-0.31.0.tgz",
+ "integrity": "sha512-UKk3psvA1cRbk4/c9CkpWB8mdWrkKvzw0DmEYRsWolUQytQ2cRqx+hYuV6ZCsngw/xbj9hpmkZmAZEyq2g4fMg==",
+ "dependencies": {
+ "@panva/hkdf": "^1.1.1",
+ "@types/cookie": "0.6.0",
+ "cookie": "0.6.0",
+ "jose": "^5.1.3",
+ "oauth4webapi": "^2.4.0",
+ "preact": "10.11.3",
+ "preact-render-to-string": "5.2.3"
+ },
+ "peerDependencies": {
+ "@simplewebauthn/browser": "^9.0.1",
+ "@simplewebauthn/server": "^9.0.2",
+ "nodemailer": "^6.8.0"
+ },
+ "peerDependenciesMeta": {
+ "@simplewebauthn/browser": {
+ "optional": true
+ },
+ "@simplewebauthn/server": {
+ "optional": true
+ },
+ "nodemailer": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@babel/runtime": {
"version": "7.24.5",
"resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.5.tgz",
@@ -632,6 +665,14 @@
"node": ">= 8"
}
},
+ "node_modules/@panva/hkdf": {
+ "version": "1.1.1",
+ "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.1.1.tgz",
+ "integrity": "sha512-dhPeilub1NuIG0X5Kvhh9lH4iW3ZsHlnzwgwbOlgwQ2wG1IqFzsgHqmKPk3WzsdWAeaxKJxgM0+W433RmN45GA==",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/@pkgjs/parseargs": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
@@ -1478,6 +1519,20 @@
"tslib": "^2.4.0"
}
},
+ "node_modules/@types/bcrypt": {
+ "version": "5.0.2",
+ "resolved": "https://registry.npmjs.org/@types/bcrypt/-/bcrypt-5.0.2.tgz",
+ "integrity": "sha512-6atioO8Y75fNcbmj0G7UjI9lXN2pQ/IGJ2FWT4a/btd0Lk9lQalHLKhkgKVZ3r+spnmWUKfbMi1GEe9wyHQfNQ==",
+ "dev": true,
+ "dependencies": {
+ "@types/node": "*"
+ }
+ },
+ "node_modules/@types/cookie": {
+ "version": "0.6.0",
+ "resolved": "https://registry.npmjs.org/@types/cookie/-/cookie-0.6.0.tgz",
+ "integrity": "sha512-4Kh9a6B2bQciAhf7FSuMRRkUWecJgJu9nPnx3yzpsfXX/c50REIqpHY4C82bXP90qrLtXtkDxTZosYO3UpOwlA=="
+ },
"node_modules/@types/d3-color": {
"version": "3.1.3",
"resolved": "https://registry.npmjs.org/@types/d3-color/-/d3-color-3.1.3.tgz",
@@ -2026,6 +2081,11 @@
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
"integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw=="
},
+ "node_modules/bcryptjs": {
+ "version": "2.4.3",
+ "resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
+ "integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ=="
+ },
"node_modules/binary-extensions": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
@@ -2236,6 +2296,14 @@
"integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==",
"dev": true
},
+ "node_modules/cookie": {
+ "version": "0.6.0",
+ "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz",
+ "integrity": "sha512-U71cyTamuh1CRNCfpGY6to28lxvNwPG4Guz/EVjgf3Jmzv0vlDp1atT9eS5dDjMYHucpHbWns6Lwf3BKz6svdw==",
+ "engines": {
+ "node": ">= 0.6"
+ }
+ },
"node_modules/cross-spawn": {
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz",
@@ -4081,6 +4149,14 @@
"jiti": "bin/jiti.js"
}
},
+ "node_modules/jose": {
+ "version": "5.3.0",
+ "resolved": "https://registry.npmjs.org/jose/-/jose-5.3.0.tgz",
+ "integrity": "sha512-IChe9AtAE79ru084ow8jzkN2lNrG3Ntfiv65Cvj9uOCE2m5LNsdHG+9EbxWxAoWRF9TgDOqLN5jm08++owDVRg==",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/js-tokens": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -4386,6 +4462,32 @@
}
}
},
+ "node_modules/next-auth": {
+ "version": "5.0.0-beta.18",
+ "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-5.0.0-beta.18.tgz",
+ "integrity": "sha512-x55L8wZb8PcPGCYA3e/l9tdpd7YL3FDuhas4W8pxq3PjrWJ9OoDxNN0otK9axJamJBbBgjfzTJjVQB6hXoe0ZQ==",
+ "dependencies": {
+ "@auth/core": "0.31.0"
+ },
+ "peerDependencies": {
+ "@simplewebauthn/browser": "^9.0.1",
+ "@simplewebauthn/server": "^9.0.2",
+ "next": "^14",
+ "nodemailer": "^6.6.5",
+ "react": "^18.2.0"
+ },
+ "peerDependenciesMeta": {
+ "@simplewebauthn/browser": {
+ "optional": true
+ },
+ "@simplewebauthn/server": {
+ "optional": true
+ },
+ "nodemailer": {
+ "optional": true
+ }
+ }
+ },
"node_modules/next-themes": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/next-themes/-/next-themes-0.3.0.tgz",
@@ -4430,6 +4532,14 @@
"node": ">=0.10.0"
}
},
+ "node_modules/oauth4webapi": {
+ "version": "2.10.4",
+ "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-2.10.4.tgz",
+ "integrity": "sha512-DSoj8QoChzOCQlJkRmYxAJCIpnXFW32R0Uq7avyghIeB6iJq0XAblOD7pcq3mx4WEBDwMuKr0Y1qveCBleG2Xw==",
+ "funding": {
+ "url": "https://github.com/sponsors/panva"
+ }
+ },
"node_modules/object-assign": {
"version": "4.1.1",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz",
@@ -4867,6 +4977,26 @@
"resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.2.0.tgz",
"integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ=="
},
+ "node_modules/preact": {
+ "version": "10.11.3",
+ "resolved": "https://registry.npmjs.org/preact/-/preact-10.11.3.tgz",
+ "integrity": "sha512-eY93IVpod/zG3uMF22Unl8h9KkrcKIRs2EGar8hwLZZDU1lkjph303V9HZBwufh2s736U6VXuhD109LYqPoffg==",
+ "funding": {
+ "type": "opencollective",
+ "url": "https://opencollective.com/preact"
+ }
+ },
+ "node_modules/preact-render-to-string": {
+ "version": "5.2.3",
+ "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.3.tgz",
+ "integrity": "sha512-aPDxUn5o3GhWdtJtW0svRC2SS/l8D9MAgo2+AWml+BhDImb27ALf04Q2d+AHqUUOc6RdSXFIBVa2gxzgMKgtZA==",
+ "dependencies": {
+ "pretty-format": "^3.8.0"
+ },
+ "peerDependencies": {
+ "preact": ">=10"
+ }
+ },
"node_modules/prelude-ls": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
@@ -4876,6 +5006,11 @@
"node": ">= 0.8.0"
}
},
+ "node_modules/pretty-format": {
+ "version": "3.8.0",
+ "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz",
+ "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew=="
+ },
"node_modules/prisma": {
"version": "5.14.0",
"resolved": "https://registry.npmjs.org/prisma/-/prisma-5.14.0.tgz",
diff --git a/package.json b/package.json
index feab765..f59b436 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,8 @@
"dev": "next dev",
"build": "next build",
"start": "next start",
- "lint": "next lint"
+ "lint": "next lint",
+ "seed": "node ./scripts/seed.js"
},
"dependencies": {
"@hookform/resolvers": "^3.4.2",
@@ -21,10 +22,12 @@
"@radix-ui/react-progress": "^1.0.3",
"@radix-ui/react-slot": "^1.0.2",
"@radix-ui/react-tooltip": "^1.0.7",
+ "bcryptjs": "^2.4.3",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.1",
"lucide-react": "^0.379.0",
"next": "14.2.3",
+ "next-auth": "^5.0.0-beta.18",
"next-themes": "^0.3.0",
"react": "^18",
"react-dom": "^18",
@@ -34,6 +37,7 @@
"zod": "^3.23.8"
},
"devDependencies": {
+ "@types/bcrypt": "^5.0.2",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
diff --git a/prisma/migrations/20240528002543_add_string_id_to_user/migration.sql b/prisma/migrations/20240528002543_add_string_id_to_user/migration.sql
new file mode 100644
index 0000000..d923a94
--- /dev/null
+++ b/prisma/migrations/20240528002543_add_string_id_to_user/migration.sql
@@ -0,0 +1,120 @@
+/*
+ Warnings:
+
+ - The primary key for the `Job` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `Company` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `JobSource` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `Interview` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `Contact` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `JobStatus` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `JobTitle` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `User` table will be changed. If it partially fails, the table could be left without primary key constraint.
+ - The primary key for the `Location` table will be changed. If it partially fails, the table could be left without primary key constraint.
+
+*/
+-- RedefineTables
+PRAGMA foreign_keys=OFF;
+CREATE TABLE "new_Job" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "userId" TEXT NOT NULL,
+ "description" TEXT NOT NULL,
+ "createdAt" DATETIME NOT NULL,
+ "appliedDate" DATETIME,
+ "dueDate" DATETIME,
+ "statusId" TEXT NOT NULL,
+ "jobTitleId" TEXT NOT NULL,
+ "companyId" TEXT NOT NULL,
+ "jobSourceId" TEXT,
+ "salaryRange" TEXT,
+ "locationId" TEXT,
+ CONSTRAINT "Job_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_statusId_fkey" FOREIGN KEY ("statusId") REFERENCES "JobStatus" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_jobTitleId_fkey" FOREIGN KEY ("jobTitleId") REFERENCES "JobTitle" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_companyId_fkey" FOREIGN KEY ("companyId") REFERENCES "Company" ("id") ON DELETE RESTRICT ON UPDATE CASCADE,
+ CONSTRAINT "Job_jobSourceId_fkey" FOREIGN KEY ("jobSourceId") REFERENCES "JobSource" ("id") ON DELETE SET NULL ON UPDATE CASCADE,
+ CONSTRAINT "Job_locationId_fkey" FOREIGN KEY ("locationId") REFERENCES "Location" ("id") ON DELETE SET NULL ON UPDATE CASCADE
+);
+INSERT INTO "new_Job" ("appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "locationId", "salaryRange", "statusId", "userId") SELECT "appliedDate", "companyId", "createdAt", "description", "dueDate", "id", "jobSourceId", "jobTitleId", "locationId", "salaryRange", "statusId", "userId" FROM "Job";
+DROP TABLE "Job";
+ALTER TABLE "new_Job" RENAME TO "Job";
+CREATE TABLE "new_Company" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "logoUrl" TEXT
+);
+INSERT INTO "new_Company" ("id", "logoUrl", "name") SELECT "id", "logoUrl", "name" FROM "Company";
+DROP TABLE "Company";
+ALTER TABLE "new_Company" RENAME TO "Company";
+CREATE UNIQUE INDEX "Company_name_key" ON "Company"("name");
+CREATE TABLE "new_JobSource" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL
+);
+INSERT INTO "new_JobSource" ("id", "name") SELECT "id", "name" FROM "JobSource";
+DROP TABLE "JobSource";
+ALTER TABLE "new_JobSource" RENAME TO "JobSource";
+CREATE TABLE "new_Interview" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "jobId" TEXT NOT NULL,
+ CONSTRAINT "Interview_jobId_fkey" FOREIGN KEY ("jobId") REFERENCES "Job" ("id") ON DELETE RESTRICT ON UPDATE CASCADE
+);
+INSERT INTO "new_Interview" ("id", "jobId") SELECT "id", "jobId" FROM "Interview";
+DROP TABLE "Interview";
+ALTER TABLE "new_Interview" RENAME TO "Interview";
+CREATE TABLE "new_Contact" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "email" TEXT NOT NULL,
+ "interviewId" TEXT,
+ CONSTRAINT "Contact_interviewId_fkey" FOREIGN KEY ("interviewId") REFERENCES "Interview" ("id") ON DELETE SET NULL ON UPDATE CASCADE
+);
+INSERT INTO "new_Contact" ("email", "id", "interviewId", "name") SELECT "email", "id", "interviewId", "name" FROM "Contact";
+DROP TABLE "Contact";
+ALTER TABLE "new_Contact" RENAME TO "Contact";
+CREATE TABLE "new_JobStatus" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "statusName" TEXT NOT NULL
+);
+INSERT INTO "new_JobStatus" ("id", "statusName") SELECT "id", "statusName" FROM "JobStatus";
+DROP TABLE "JobStatus";
+ALTER TABLE "new_JobStatus" RENAME TO "JobStatus";
+CREATE UNIQUE INDEX "JobStatus_statusName_key" ON "JobStatus"("statusName");
+CREATE TABLE "new_JobTitle" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "title" TEXT NOT NULL
+);
+INSERT INTO "new_JobTitle" ("id", "title") SELECT "id", "title" FROM "JobTitle";
+DROP TABLE "JobTitle";
+ALTER TABLE "new_JobTitle" RENAME TO "JobTitle";
+CREATE UNIQUE INDEX "JobTitle_title_key" ON "JobTitle"("title");
+CREATE TABLE "new_User" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "email" TEXT NOT NULL,
+ "password" TEXT NOT NULL,
+ "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP
+);
+INSERT INTO "new_User" ("createdAt", "email", "id", "name", "password") SELECT "createdAt", "email", "id", "name", "password" FROM "User";
+DROP TABLE "User";
+ALTER TABLE "new_User" RENAME TO "User";
+CREATE UNIQUE INDEX "User_email_key" ON "User"("email");
+CREATE TABLE "new_Location" (
+ "id" TEXT NOT NULL PRIMARY KEY,
+ "name" TEXT NOT NULL,
+ "state" TEXT,
+ "country" TEXT NOT NULL
+);
+INSERT INTO "new_Location" ("country", "id", "name", "state") SELECT "country", "id", "name", "state" FROM "Location";
+DROP TABLE "Location";
+ALTER TABLE "new_Location" RENAME TO "Location";
+CREATE UNIQUE INDEX "Location_name_key" ON "Location"("name");
+PRAGMA foreign_key_check("Job");
+PRAGMA foreign_key_check("Company");
+PRAGMA foreign_key_check("JobSource");
+PRAGMA foreign_key_check("Interview");
+PRAGMA foreign_key_check("Contact");
+PRAGMA foreign_key_check("JobStatus");
+PRAGMA foreign_key_check("JobTitle");
+PRAGMA foreign_key_check("User");
+PRAGMA foreign_key_check("Location");
+PRAGMA foreign_keys=ON;
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index 0f4941d..578748d 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -11,7 +11,7 @@ datasource db {
}
model User {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
name String
email String @unique
password String
@@ -20,27 +20,27 @@ model User {
}
model Contact {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
name String
email String
Interview Interview? @relation(fields: [interviewId], references: [id])
- interviewId Int?
+ interviewId String?
}
model JobTitle {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
title String @unique
jobs Job[]
}
model JobStatus {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
statusName String @unique
jobs Job[]
}
model Location {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
name String @unique
state String?
country String
@@ -48,43 +48,43 @@ model Location {
}
model Company {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
name String @unique
jobsApplied Job[]
logoUrl String? // field is optional
}
model JobSource {
- id Int @id @default(autoincrement())
+ id String @id @default(uuid())
name String
jobsApplied Job[]
}
model Interview {
- id Int @id @default(autoincrement())
- jobId Int
+ id String @id @default(uuid())
+ jobId String
job Job? @relation(fields: [jobId], references: [id])
interviewers Contact[]
}
model Job {
- id Int @id @default(autoincrement())
- userId Int
+ id String @id @default(uuid())
+ userId String
User User @relation(fields: [userId], references: [id])
description String
createdAt DateTime
appliedDate DateTime?
dueDate DateTime?
- statusId Int
+ statusId String
Status JobStatus @relation(fields: [statusId], references: [id])
JobTitle JobTitle @relation(fields: [jobTitleId], references: [id])
- jobTitleId Int
+ jobTitleId String
Company Company @relation(fields: [companyId], references: [id])
- companyId Int
+ companyId String
JobSource JobSource? @relation(fields: [jobSourceId], references: [id])
- jobSourceId Int?
+ jobSourceId String?
salaryRange String?
Location Location? @relation(fields: [locationId], references: [id])
- locationId Int?
+ locationId String?
Interview Interview[]
}
diff --git a/scripts/seed.js b/scripts/seed.js
new file mode 100644
index 0000000..fd2c852
--- /dev/null
+++ b/scripts/seed.js
@@ -0,0 +1,31 @@
+
+const { PrismaClient } = require('@prisma/client');
+const bcrypt = require('bcryptjs');
+
+const prisma = new PrismaClient();
+
+async function main() {
+ const password = await bcrypt.hash('password123', 10);
+
+ const user1 = await prisma.user.upsert({
+ where: { email: '[email protected]' },
+ update: {},
+ create: {
+ email: '[email protected]',
+ name: 'Admin',
+ password,
+ },
+ });
+
+
+ console.log({ user1 });
+ }
+
+ main()
+ .catch((e) => {
+ console.error(e);
+ process.exit(1);
+ })
+ .finally(async () => {
+ await prisma.$disconnect();
+ });
\ No newline at end of file
diff --git a/src/actions/auth.actions.ts b/src/actions/auth.actions.ts
new file mode 100644
index 0000000..870ef46
--- /dev/null
+++ b/src/actions/auth.actions.ts
@@ -0,0 +1,22 @@
+"use server";
+import { AuthError } from "next-auth";
+import { signIn } from "../auth";
+
+export async function authenticate(
+ prevState: string | undefined,
+ formData: FormData
+) {
+ try {
+ await signIn("credentials", formData);
+ } catch (error) {
+ if (error instanceof AuthError) {
+ switch (error.type) {
+ case "CredentialsSignin":
+ return "Invalid credentials.";
+ default:
+ return "Something went wrong.";
+ }
+ }
+ throw error;
+ }
+}
diff --git a/src/app/(auth)/signin/page.tsx b/src/app/(auth)/signin/page.tsx
index 179393a..6f0c934 100644
--- a/src/app/(auth)/signin/page.tsx
+++ b/src/app/(auth)/signin/page.tsx
@@ -21,6 +21,9 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
+import { useFormState, useFormStatus } from "react-dom";
+import { ArrowRightIcon } from "lucide-react";
+import { authenticate } from "@/actions/auth.actions";
const FormSchema = z.object({
email: z
@@ -41,9 +44,9 @@ export default function Signin() {
resolver: zodResolver(FormSchema),
});
- function onSubmit(data: z.infer<typeof FormSchema>) {
- console.log("onsubmit data: ", data);
- }
+ const [errorMessage, dispatch] = useFormState(authenticate, undefined);
+
+ const { pending } = useFormStatus();
return (
<Card className="mx-auto max-w-sm">
@@ -56,7 +59,7 @@ export default function Signin() {
<CardContent>
<Form {...form}>
<form
- onSubmit={form.handleSubmit(onSubmit)}
+ action={dispatch}
// className="w-2/3 space-y-6"
>
<div className="grid gap-4">
@@ -97,9 +100,20 @@ export default function Signin() {
{/* </div> */}
{/* <Input id="password" type="password" required /> */}
</div>
- <Button type="submit" className="w-full">
+ <Button aria-disabled={pending} className="w-full">
Login
</Button>
+ <div
+ className="flex h-8 items-end space-x-1"
+ aria-live="polite"
+ aria-atomic="true"
+ >
+ {errorMessage && (
+ <>
+ <p className="text-sm text-red-500">{errorMessage}</p>
+ </>
+ )}
+ </div>
</div>
</form>
</Form>
diff --git a/src/app/(dashboard)/activities/page.tsx b/src/app/dashboard/activities/page.tsx
similarity index 100%
rename from src/app/(dashboard)/activities/page.tsx
rename to src/app/dashboard/activities/page.tsx
diff --git a/src/app/(dashboard)/layout.tsx b/src/app/dashboard/layout.tsx
similarity index 100%
rename from src/app/(dashboard)/layout.tsx
rename to src/app/dashboard/layout.tsx
diff --git a/src/app/(dashboard)/myjobs/page.tsx b/src/app/dashboard/myjobs/page.tsx
similarity index 100%
rename from src/app/(dashboard)/myjobs/page.tsx
rename to src/app/dashboard/myjobs/page.tsx
diff --git a/src/app/(dashboard)/page.tsx b/src/app/dashboard/page.tsx
similarity index 100%
rename from src/app/(dashboard)/page.tsx
rename to src/app/dashboard/page.tsx
diff --git a/src/app/(dashboard)/profile/page.tsx b/src/app/dashboard/profile/page.tsx
similarity index 100%
rename from src/app/(dashboard)/profile/page.tsx
rename to src/app/dashboard/profile/page.tsx
diff --git a/src/app/(dashboard)/settings/page.tsx b/src/app/dashboard/settings/page.tsx
similarity index 100%
rename from src/app/(dashboard)/settings/page.tsx
rename to src/app/dashboard/settings/page.tsx
diff --git a/src/auth.config.ts b/src/auth.config.ts
new file mode 100644
index 0000000..73d3f0c
--- /dev/null
+++ b/src/auth.config.ts
@@ -0,0 +1,26 @@
+import type { NextAuthConfig } from "next-auth";
+
+export const authConfig = {
+ pages: {
+ signIn: "/signin",
+ error: "/signin",
+ },
+ callbacks: {
+ authorized({ auth, request: { nextUrl } }) {
+ console.log("auth: ", auth);
+ console.log("PATHNAME: ", nextUrl);
+ const isLoggedIn = !!auth?.user;
+ const isOnDashboard = nextUrl.pathname.startsWith("/dashboard");
+ console.log("isOnDashboard: ", isOnDashboard);
+
+ if (isOnDashboard) {
+ if (isLoggedIn) return true;
+ return false; // Redirect unauthenticated users to login page
+ } else if (isLoggedIn) {
+ return Response.redirect(new URL("/dashboard", nextUrl));
+ }
+ return true;
+ },
+ },
+ providers: [], // Add providers with an empty array for now
+} satisfies NextAuthConfig;
diff --git a/src/auth.ts b/src/auth.ts
new file mode 100644
index 0000000..08a0812
--- /dev/null
+++ b/src/auth.ts
@@ -0,0 +1,46 @@
+import NextAuth from "next-auth";
+import Credentials from "next-auth/providers/credentials";
+import { z } from "zod";
+var bcrypt = require("bcryptjs");
+import { PrismaClient } from "@prisma/client";
+import { authConfig } from "./auth.config";
+import { User } from "./models/user";
+
+const prisma = new PrismaClient();
+
+async function getUser(email: string): Promise<User | undefined> {
+ try {
+ const user = await prisma.user.findUnique({
+ where: { email },
+ });
+ return user || undefined;
+ } catch (error) {
+ console.error("Failed to fetch user:", error);
+ throw new Error("Failed to fetch user.");
+ }
+}
+
+export const { auth, signIn, signOut } = NextAuth({
+ ...authConfig,
+ providers: [
+ Credentials({
+ async authorize(credentials) {
+ const parsedCredentials = z
+ .object({ email: z.string().email(), password: z.string().min(6) })
+ .safeParse(credentials);
+
+ if (parsedCredentials.success) {
+ const { email, password } = parsedCredentials.data;
+ const user = await getUser(email);
+ console.log("returnd user: ", user);
+ if (!user) return null;
+ const passwordsMatch = await bcrypt.compare(password, user.password);
+ console.log("passwordmatch", passwordsMatch);
+ if (passwordsMatch) return user;
+ }
+ console.log("Invalid credentials");
+ return null;
+ },
+ }),
+ ],
+});
diff --git a/src/middleware.ts b/src/middleware.ts
new file mode 100644
index 0000000..089cbb4
--- /dev/null
+++ b/src/middleware.ts
@@ -0,0 +1,9 @@
+import NextAuth from "next-auth";
+import { authConfig } from "./auth.config";
+
+export default NextAuth(authConfig).auth;
+
+export const config = {
+ // https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
+ matcher: ["/((?!api|_next/static|_next/image|.*\\.png$).*)", "/dashboard"],
+};
diff --git a/src/models/user.ts b/src/models/user.ts
new file mode 100644
index 0000000..2a80a3d
--- /dev/null
+++ b/src/models/user.ts
@@ -0,0 +1,6 @@
+export interface User {
+ id: string;
+ name: string;
+ email: string;
+ password: string;
+}