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.

Fix: Missing user validations

Khuram Niazf43742913813
diff --git a/src/actions/company.actions.ts b/src/actions/company.actions.ts
index b1c50a3..a1ff46e 100644
--- a/src/actions/company.actions.ts
+++ b/src/actions/company.actions.ts
@@ -159,8 +159,8 @@ export const updateCompany = async (
const { id, company, logoUrl, createdBy } = data;
- if (!id || user.id != createdBy) {
- throw new Error("Id is not provided or no user privilages");
+ if (!id) {
+ throw new Error("Company id is required");
}
// Validate image URL
@@ -186,6 +186,7 @@ export const updateCompany = async (
const res = await prisma.company.update({
where: {
id,
+ createdBy: user.id,
},
data: {
value,
@@ -217,6 +218,7 @@ export const getCompanyById = async (
const company = await prisma.company.findUnique({
where: {
id: companyId,
+ createdBy: user.id,
},
});
return company;
diff --git a/src/actions/coverLetter.actions.ts b/src/actions/coverLetter.actions.ts
index 923e1de..81a5730 100644
--- a/src/actions/coverLetter.actions.ts
+++ b/src/actions/coverLetter.actions.ts
@@ -122,7 +122,7 @@ export const updateCoverLetter = async (
}
const res = await prisma.coverLetter.update({
- where: { id },
+ where: { id, profile: { userId: user.id } },
data: { title, content },
});
@@ -143,7 +143,7 @@ export const deleteCoverLetterById = async (
}
await prisma.coverLetter.delete({
- where: { id: coverLetterId },
+ where: { id: coverLetterId, profile: { userId: user.id } },
});
return { success: true };
diff --git a/src/actions/job.actions.ts b/src/actions/job.actions.ts
index 2f69d2a..06eafeb 100644
--- a/src/actions/job.actions.ts
+++ b/src/actions/job.actions.ts
@@ -178,6 +178,7 @@ export const getJobDetails = async (
const job = await prisma.job.findUnique({
where: {
id: jobId,
+ userId: user.id,
},
include: {
JobSource: true,
@@ -338,8 +339,8 @@ export const updateJob = async (
if (!user) {
throw new Error("Not authenticated");
}
- if (!data.id || user.id != data.userId) {
- throw new Error("Id is not provide or no user privilages");
+ if (!data.id) {
+ throw new Error("Job id is required");
}
const {
@@ -366,6 +367,7 @@ export const updateJob = async (
const job = await prisma.job.update({
where: {
id,
+ userId: user.id,
},
data: {
jobTitleId: title,
diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.ts
index 5ab49dd..88b686a 100644
--- a/src/actions/profile.actions.ts
+++ b/src/actions/profile.actions.ts
@@ -83,6 +83,7 @@ export const getResumeById = async (
const resume = await prisma.resume.findUnique({
where: {
id: resumeId,
+ profile: { userId: user.id },
},
include: {
ContactInfo: true,
@@ -126,6 +127,7 @@ export const addContactInfo = async (
const res = await prisma.resume.update({
where: {
id: data.resumeId,
+ profile: { userId: user.id },
},
data: {
ContactInfo: {
@@ -164,6 +166,7 @@ export const updateContactInfo = async (
const res = await prisma.contactInfo.update({
where: {
id: data.id,
+ resume: { profile: { userId: user.id } },
},
data: {
firstName: data.firstName,
@@ -287,8 +290,13 @@ export const editResume = async (
}
}
+ const user = await getCurrentUser();
+ if (!user) {
+ throw new Error("Not authenticated");
+ }
+
const res = await prisma.resume.update({
- where: { id },
+ where: { id, profile: { userId: user.id } },
data: {
title,
FileId: resolvedFileId || null,
@@ -452,6 +460,7 @@ export const updateResumeSummary = async (
const res = await prisma.resumeSection.update({
where: {
id: data.id,
+ Resume: { profile: { userId: user.id } },
},
data: {
sectionTitle: data.sectionTitle!,
@@ -461,6 +470,7 @@ export const updateResumeSummary = async (
const summary = await prisma.resumeSection.update({
where: {
id: data.id,
+ Resume: { profile: { userId: user.id } },
},
data: {
summary: {
@@ -548,6 +558,7 @@ export const updateExperience = async (
const summary = await prisma.workExperience.update({
where: {
id: data.id,
+ ResumeSection: { Resume: { profile: { userId: user.id } } },
},
data: {
jobTitleId: data.title,
@@ -632,6 +643,7 @@ export const updateEducation = async (
const summary = await prisma.education.update({
where: {
id: data.id,
+ ResumeSection: { Resume: { profile: { userId: user.id } } },
},
data: {
institution: data.institution,