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 signup logic

Khuram Niaz94c4af6d2f0f
diff --git a/package-lock.json b/package-lock.json
index 7c88263..347254e 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "jobsync",
- "version": "0.2.2",
+ "version": "0.2.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "jobsync",
- "version": "0.2.2",
+ "version": "0.2.3",
"dependencies": {
"@ai-sdk/deepseek": "^2.0.4",
"@ai-sdk/openai": "^3.0.2",
@@ -46,7 +46,7 @@
"date-fns": "^3.6.0",
"lucide-react": "^0.469.0",
"next": "15.5.10",
- "next-auth": "^5.0.0-beta.25",
+ "next-auth": "^5.0.0-beta.30",
"next-themes": "^0.4.4",
"node-cron": "^4.2.1",
"ollama-ai-provider-v2": "^2.0.0",
@@ -66,7 +66,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
- "@types/bcrypt": "^5.0.2",
+ "@types/bcryptjs": "^2.4.6",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.2",
"@types/node-cron": "^3.0.11",
@@ -4642,15 +4642,12 @@
"@babel/types": "^7.28.2"
}
},
- "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==",
+ "node_modules/@types/bcryptjs": {
+ "version": "2.4.6",
+ "resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.6.tgz",
+ "integrity": "sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ==",
"dev": true,
- "license": "MIT",
- "dependencies": {
- "@types/node": "*"
- }
+ "license": "MIT"
},
"node_modules/@types/d3-array": {
"version": "3.2.2",
diff --git a/package.json b/package.json
index 139216b..c92194c 100644
--- a/package.json
+++ b/package.json
@@ -51,7 +51,7 @@
"date-fns": "^3.6.0",
"lucide-react": "^0.469.0",
"next": "15.5.10",
- "next-auth": "^5.0.0-beta.25",
+ "next-auth": "^5.0.0-beta.30",
"next-themes": "^0.4.4",
"node-cron": "^4.2.1",
"ollama-ai-provider-v2": "^2.0.0",
@@ -71,7 +71,7 @@
"@testing-library/jest-dom": "^6.6.3",
"@testing-library/react": "^16.1.0",
"@testing-library/user-event": "^14.5.2",
- "@types/bcrypt": "^5.0.2",
+ "@types/bcryptjs": "^2.4.6",
"@types/jest": "^30.0.0",
"@types/node": "^22.10.2",
"@types/node-cron": "^3.0.11",
diff --git a/src/actions/auth.actions.ts b/src/actions/auth.actions.ts
index 1bf6645..afb1d7b 100644
--- a/src/actions/auth.actions.ts
+++ b/src/actions/auth.actions.ts
@@ -2,6 +2,38 @@
import { AuthError } from "next-auth";
import { signIn } from "../auth";
import { delay } from "@/utils/delay";
+import prisma from "@/lib/db";
+import bcrypt from "bcryptjs";
+import { SignupFormSchema } from "@/models/signupForm.schema";
+
+export async function signup(formData: {
+ name: string;
+ email: string;
+ password: string;
+}) {
+ const parsed = SignupFormSchema.safeParse(formData);
+ if (!parsed.success) {
+ return { error: "Invalid form data." };
+ }
+
+ const { name, email, password } = parsed.data;
+
+ const existingUser = await prisma.user.findUnique({
+ where: { email },
+ });
+
+ if (existingUser) {
+ return { error: "An account with this email already exists." };
+ }
+
+ const hashedPassword = await bcrypt.hash(password, 10);
+
+ await prisma.user.create({
+ data: { name, email, password: hashedPassword },
+ });
+
+ return { success: true };
+}
export async function authenticate(
prevState: string | undefined,
diff --git a/src/app/(auth)/signup/page.tsx b/src/app/(auth)/signup/page.tsx
index 2d9eb2c..317529c 100644
--- a/src/app/(auth)/signup/page.tsx
+++ b/src/app/(auth)/signup/page.tsx
@@ -1,7 +1,5 @@
-"use client";
import Link from "next/link";
-import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
@@ -9,52 +7,14 @@ import {
CardHeader,
CardTitle,
} from "@/components/ui/card";
-import { Input } from "@/components/ui/input";
-import { z } from "zod";
-import { useForm } from "react-hook-form";
-import { zodResolver } from "@hookform/resolvers/zod";
-import {
- Form,
- FormControl,
- FormField,
- FormItem,
- FormLabel,
- FormMessage,
-} from "@/components/ui/form";
+import { Metadata } from "next";
+import SignupForm from "@/components/auth/SignupForm";
-const FormSchema = z.object({
- name: z.string().min(2, {
- message: "Name must be at least 2 characters.",
- }),
- email: z
- .string({
- error: "Email is required.",
- })
- .min(3, {
- message: "Email must be at least 3 characters.",
- })
- .email("Please enter a valid email."),
- password: z
- .string({
- error: "Please enter your password.",
- })
- .min(6, {
- message: "Password must be at least 6 characters.",
- }),
-});
+export const metadata: Metadata = {
+ title: "Signup",
+};
export default function Signup() {
- const form = useForm<z.infer<typeof FormSchema>>({
- resolver: zodResolver(FormSchema),
- // defaultValues: {
- // username: "",
- // },
- });
-
- function onSubmit(data: z.infer<typeof FormSchema>) {
- console.log("onsubmit data: ", data);
- }
-
return (
<Card className="mx-auto max-w-sm">
<CardHeader>
@@ -64,63 +24,7 @@ export default function Signup() {
</CardDescription>
</CardHeader>
<CardContent>
- <Form {...form}>
- <form
- // className="w-2/3 space-y-6"
- >
- <div className="grid gap-4">
- <div className="grid gap-2">
- <FormField
- control={form.control}
- name="name"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Full Name</FormLabel>
- <FormControl>
- <Input placeholder="Your Name" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </div>
- <div className="grid gap-2">
- <FormField
- control={form.control}
- name="email"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Email</FormLabel>
- <FormControl>
- <Input placeholder="[email protected]" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </div>
- <div className="grid gap-2">
- <FormField
- control={form.control}
- name="password"
- render={({ field }) => (
- <FormItem>
- <FormLabel>Password</FormLabel>
- <FormControl>
- <Input type="password" {...field} />
- </FormControl>
- <FormMessage />
- </FormItem>
- )}
- />
- </div>
- <Button type="submit" className="w-full">
- Create an account
- </Button>
- </div>
- </form>
- </Form>
-
+ <SignupForm />
<div className="mt-4 text-center text-sm">
Already have an account?{" "}
<Link href="/signin" className="underline">
diff --git a/src/app/api/ai/resume/match/route.ts b/src/app/api/ai/resume/match/route.ts
index 0d6d3be..1fc40b9 100644
--- a/src/app/api/ai/resume/match/route.ts
+++ b/src/app/api/ai/resume/match/route.ts
@@ -23,9 +23,9 @@ import { AiModel } from "@/models/ai.model";
*/
export const POST = async (req: NextRequest) => {
const session = await auth();
- const userId = session?.accessToken?.sub;
+ const userId = session?.user?.id;
- if (!session || !session.user || !userId) {
+ if (!session || !userId) {
return NextResponse.json({ message: "Not Authenticated" }, { status: 401 });
}
diff --git a/src/app/api/ai/resume/review/route.ts b/src/app/api/ai/resume/review/route.ts
index e056dfe..5f151d7 100644
--- a/src/app/api/ai/resume/review/route.ts
+++ b/src/app/api/ai/resume/review/route.ts
@@ -21,9 +21,9 @@ import { AiModel } from "@/models/ai.model";
*/
export const POST = async (req: NextRequest) => {
const session = await auth();
- const userId = session?.accessToken?.sub;
+ const userId = session?.user?.id;
- if (!session || !session.user || !userId) {
+ if (!session || !userId) {
return NextResponse.json({ message: "Not Authenticated" }, { status: 401 });
}
diff --git a/src/app/api/automations/[id]/logs/clear/route.ts b/src/app/api/automations/[id]/logs/clear/route.ts
index 4639ca9..08823a6 100644
--- a/src/app/api/automations/[id]/logs/clear/route.ts
+++ b/src/app/api/automations/[id]/logs/clear/route.ts
@@ -8,9 +8,9 @@ export async function POST(
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth();
- const userId = session?.accessToken?.sub;
+ const userId = session?.user?.id;
- if (!session || !session.user || !userId) {
+ if (!session || !userId) {
return NextResponse.json({ message: "Not Authenticated" }, { status: 401 });
}
diff --git a/src/app/api/automations/[id]/logs/route.ts b/src/app/api/automations/[id]/logs/route.ts
index 9a3db0c..f9fa166 100644
--- a/src/app/api/automations/[id]/logs/route.ts
+++ b/src/app/api/automations/[id]/logs/route.ts
@@ -23,9 +23,9 @@ export async function GET(
{ params }: { params: Promise<{ id: string }> },
) {
const session = await auth();
- const userId = session?.accessToken?.sub;
+ const userId = session?.user?.id;
- if (!session || !session.user || !userId) {
+ if (!session || !userId) {
return createSSEErrorResponse("Not Authenticated");
}
diff --git a/src/app/api/automations/[id]/run/route.ts b/src/app/api/automations/[id]/run/route.ts
index 5fea3f2..5b289c2 100644
--- a/src/app/api/automations/[id]/run/route.ts
+++ b/src/app/api/automations/[id]/run/route.ts
@@ -31,9 +31,9 @@ export async function POST(
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth();
- const userId = session?.accessToken?.sub;
+ const userId = session?.user?.id;
- if (!session || !session.user || !userId) {
+ if (!session || !userId) {
return NextResponse.json({ message: "Not Authenticated" }, { status: 401 });
}
diff --git a/src/app/api/profile/resume/route.ts b/src/app/api/profile/resume/route.ts
index 812e6ec..54762bb 100644
--- a/src/app/api/profile/resume/route.ts
+++ b/src/app/api/profile/resume/route.ts
@@ -12,7 +12,7 @@ import { getTimestampedFileName } from "@/lib/utils";
export const POST = async (req: NextRequest) => {
const session = await auth();
- const userId = session?.accessToken.sub;
+ const userId = session?.user?.id;
const dataPath = process.env.NODE_ENV !== "production" ? "data" : "/data";
let filePath;
@@ -79,7 +79,7 @@ export const POST = async (req: NextRequest) => {
export const GET = async (req: NextRequest) => {
const session = await auth();
- const userId = session?.accessToken.sub;
+ const userId = session?.user?.id;
try {
if (!session || !session.user) {
diff --git a/src/auth.config.ts b/src/auth.config.ts
index fcb6bf7..f870018 100644
--- a/src/auth.config.ts
+++ b/src/auth.config.ts
@@ -2,7 +2,11 @@ import type { NextAuthConfig } from "next-auth";
declare module "next-auth" {
interface Session {
- accessToken?: any;
+ user: {
+ id: string;
+ name?: string | null;
+ email?: string | null;
+ };
}
}
@@ -19,17 +23,25 @@ export const authConfig = {
if (isOnDashboard) {
if (isLoggedIn) return true;
- return false; // Redirect unauthenticated users to login page
+ return false;
} else if (isLoggedIn) {
return Response.redirect(new URL("/dashboard", nextUrl));
}
return true;
},
+ async jwt({ token, user }) {
+ if (user?.id) {
+ token.id = user.id;
+ }
+ return token;
+ },
async session({ session, token }) {
- // Send properties to the client, like an access_token from a provider.
- session.accessToken = token;
+ const userId = (token.id as string) || token.sub;
+ if (userId) {
+ session.user.id = userId;
+ }
return session;
},
},
- providers: [], // Add providers with an empty array for now
+ providers: [],
} satisfies NextAuthConfig;
diff --git a/src/auth.ts b/src/auth.ts
index d7eae3a..a9b9b79 100644
--- a/src/auth.ts
+++ b/src/auth.ts
@@ -1,7 +1,7 @@
import NextAuth from "next-auth";
import Credentials from "next-auth/providers/credentials";
import { z } from "zod";
-var bcrypt = require("bcryptjs");
+import bcrypt from "bcryptjs";
import { authConfig } from "./auth.config";
import { User } from "./models/user.model";
import prisma from "./lib/db";
diff --git a/src/components/auth/SignupForm.tsx b/src/components/auth/SignupForm.tsx
new file mode 100644
index 0000000..8def5a2
--- /dev/null
+++ b/src/components/auth/SignupForm.tsx
@@ -0,0 +1,124 @@
+"use client";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { useForm } from "react-hook-form";
+import { z } from "zod";
+import { signup, authenticate } from "@/actions/auth.actions";
+import {
+ Form,
+ FormControl,
+ FormField,
+ FormItem,
+ FormLabel,
+ FormMessage,
+} from "@/components/ui/form";
+import { Button } from "../ui/button";
+import { Input } from "../ui/input";
+import { useState, useTransition } from "react";
+import { useRouter } from "next/navigation";
+import { SignupFormSchema } from "@/models/signupForm.schema";
+import Loading from "../Loading";
+
+function SignupForm() {
+ const [isPending, startTransition] = useTransition();
+
+ const form = useForm<z.infer<typeof SignupFormSchema>>({
+ resolver: zodResolver(SignupFormSchema),
+ mode: "onChange",
+ defaultValues: {
+ name: "",
+ email: "",
+ password: "",
+ },
+ });
+
+ const [errorMessage, setError] = useState("");
+ const router = useRouter();
+
+ const onSubmit = async (data: z.infer<typeof SignupFormSchema>) => {
+ startTransition(async () => {
+ setError("");
+ const result = await signup(data);
+ if (result.error) {
+ setError(result.error);
+ return;
+ }
+ const formData = new FormData();
+ formData.set("email", data.email);
+ formData.set("password", data.password);
+ const authError = await authenticate("", formData);
+ if (authError) {
+ setError(authError);
+ } else {
+ router.push("/dashboard");
+ }
+ });
+ };
+
+ return (
+ <Form {...form}>
+ <form onSubmit={form.handleSubmit(onSubmit)}>
+ <div className="grid gap-4">
+ <div className="grid gap-2">
+ <FormField
+ control={form.control}
+ name="name"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Full Name</FormLabel>
+ <FormControl>
+ <Input placeholder="Your Name" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <div className="grid gap-2">
+ <FormField
+ control={form.control}
+ name="email"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Email</FormLabel>
+ <FormControl>
+ <Input placeholder="[email protected]" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <div className="grid gap-2">
+ <FormField
+ control={form.control}
+ name="password"
+ render={({ field }) => (
+ <FormItem>
+ <FormLabel>Password</FormLabel>
+ <FormControl>
+ <Input type="password" {...field} />
+ </FormControl>
+ <FormMessage />
+ </FormItem>
+ )}
+ />
+ </div>
+ <Button type="submit" disabled={isPending} className="w-full">
+ {isPending ? <Loading /> : "Create an account"}
+ </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>
+ );
+}
+
+export default SignupForm;
diff --git a/src/lib/seed.ts b/src/lib/seed.ts
index 8c76ed4..f111cdb 100644
--- a/src/lib/seed.ts
+++ b/src/lib/seed.ts
@@ -1,6 +1,5 @@
import prisma from "@/lib/db";
-// @ts-expect-error - no types for bcryptjs
import bcrypt from "bcryptjs";
const STATUS_DATA = [
diff --git a/src/models/signupForm.schema.ts b/src/models/signupForm.schema.ts
new file mode 100644
index 0000000..e581725
--- /dev/null
+++ b/src/models/signupForm.schema.ts
@@ -0,0 +1,22 @@
+import { z } from "zod";
+
+export const SignupFormSchema = z.object({
+ name: z.string().min(2, {
+ message: "Name must be at least 2 characters.",
+ }),
+ email: z
+ .string({
+ error: "Email is required.",
+ })
+ .min(3, {
+ message: "Email must be at least 3 characters.",
+ })
+ .email("Please enter a valid email."),
+ password: z
+ .string({
+ error: "Please enter your password.",
+ })
+ .min(6, {
+ message: "Password must be at least 6 characters.",
+ }),
+});
diff --git a/src/utils/user.utils.ts b/src/utils/user.utils.ts
index a75e250..9f6bb79 100644
--- a/src/utils/user.utils.ts
+++ b/src/utils/user.utils.ts
@@ -4,14 +4,11 @@ import { CurrentUser } from "@/models/user.model";
export const getCurrentUser = async () => {
const session = await auth();
- if (!session?.accessToken) return null;
- const { sub, name, email, iat, exp } = session?.accessToken;
+ if (!session?.user?.id) return null;
const user: CurrentUser = {
- id: sub,
- name,
- email,
- iat,
- exp,
+ id: session.user.id,
+ name: session.user.name ?? "",
+ email: session.user.email ?? "",
};
return user;
};