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.

refactor(automation): replace getCurrentUser with requireUser for authentication consistency across automation actions

Khuram Niaz5c904b0499df
diff --git a/src/actions/automation/analyze.ts b/src/actions/automation/analyze.ts
index 2ae312f..65f6ab6 100644
--- a/src/actions/automation/analyze.ts
+++ b/src/actions/automation/analyze.ts
@@ -1,7 +1,7 @@
"use server";
import db from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "../shared";
import { generateText } from "ai";
import {
getModel,
@@ -26,10 +26,7 @@ export async function analyzeDiscoveredJob(jobId: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const job = await db.job.findFirst({
where: { id: jobId, userId: user.id, automationId: { not: null } },
diff --git a/src/actions/automation/discoveredJobs.ts b/src/actions/automation/discoveredJobs.ts
index d330c92..a1106e4 100644
--- a/src/actions/automation/discoveredJobs.ts
+++ b/src/actions/automation/discoveredJobs.ts
@@ -1,7 +1,7 @@
"use server";
import db from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "../shared";
import type {
DiscoveredJob,
DiscoveryStatus,
@@ -24,10 +24,7 @@ export async function getDiscoveredJobs(options?: {
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const {
automationId,
@@ -106,10 +103,7 @@ export async function getDiscoveredJobById(id: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const job = await db.job.findFirst({
where: {
@@ -161,10 +155,7 @@ async function setDiscoveredJobStatus(
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const job = await db.job.findFirst({
where: {
@@ -219,10 +210,7 @@ export async function clearDiscoveredJobs(options: {
includeNew?: boolean;
}): Promise<{ success: boolean; deleted?: number; message?: string }> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const { automationId, includeNew = false } = options;
const statuses: DiscoveryStatus[] = includeNew
diff --git a/src/actions/automation/mutations.ts b/src/actions/automation/mutations.ts
index 2fc03fd..a082035 100644
--- a/src/actions/automation/mutations.ts
+++ b/src/actions/automation/mutations.ts
@@ -1,7 +1,7 @@
"use server";
import db from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "../shared";
import { calculateNextRunAt } from "@/lib/scraper/schedule";
import {
CreateAutomationSchema,
@@ -21,10 +21,7 @@ export async function createAutomation(input: CreateAutomationInput): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const validated = CreateAutomationSchema.parse(input);
@@ -108,10 +105,7 @@ export async function updateAutomation(
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const validated = UpdateAutomationSchema.parse(input);
@@ -194,10 +188,7 @@ export async function deleteAutomation(id: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const automation = await db.automation.findFirst({
where: { id, userId: user.id },
@@ -223,10 +214,7 @@ export async function pauseAutomation(id: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const automation = await db.automation.findFirst({
where: { id, userId: user.id },
@@ -266,10 +254,7 @@ export async function resumeAutomation(id: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const automation = await db.automation.findFirst({
where: { id, userId: user.id },
diff --git a/src/actions/automation/queries.ts b/src/actions/automation/queries.ts
index ef8cfdc..03a3882 100644
--- a/src/actions/automation/queries.ts
+++ b/src/actions/automation/queries.ts
@@ -1,7 +1,7 @@
"use server";
import db from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "../shared";
import type { AutomationWithResume, AutomationRun } from "@/models/automation.model";
import { APP_CONSTANTS } from "@/lib/constants";
import { formatError } from "./shared";
@@ -16,10 +16,7 @@ export async function getAutomationsList(
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const skip = (page - 1) * limit;
@@ -54,10 +51,7 @@ export async function getAutomationById(id: string): Promise<{
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const automation = await db.automation.findFirst({
where: { id, userId: user.id },
diff --git a/src/actions/automation/runs.ts b/src/actions/automation/runs.ts
index a65dc59..8611885 100644
--- a/src/actions/automation/runs.ts
+++ b/src/actions/automation/runs.ts
@@ -1,7 +1,7 @@
"use server";
import db from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "../shared";
import type { AutomationRun } from "@/models/automation.model";
import { automationLogger } from "@/lib/automation-logger";
import { formatError } from "./shared";
@@ -19,10 +19,7 @@ export async function getAutomationRuns(
message?: string;
}> {
try {
- const user = await getCurrentUser();
- if (!user) {
- return { success: false, message: "Not authenticated" };
- }
+ const user = await requireUser();
const { page = 1, limit = 10 } = options || {};
const skip = (page - 1) * limit;
@@ -59,8 +56,7 @@ export async function deleteAutomationRun(
runId: string,
): Promise<{ success: boolean; message?: string }> {
try {
- const user = await getCurrentUser();
- if (!user) return { success: false, message: "Not authenticated" };
+ const user = await requireUser();
// Ownership check via automation -> userId
const run = await db.automationRun.findFirst({
diff --git a/src/actions/resumeImport.actions.ts b/src/actions/resumeImport.actions.ts
index 02f3981..4e7d0da 100644
--- a/src/actions/resumeImport.actions.ts
+++ b/src/actions/resumeImport.actions.ts
@@ -5,7 +5,7 @@
// wrapAsHtml and getOrCreateResumeSection shared across them via ./resumeImport/shared.
import prisma from "@/lib/db";
-import { getCurrentUser } from "@/utils/user.utils";
+import { requireUser } from "./shared";
import { handleError } from "@/lib/utils";
import {
ImportContactInfo,
@@ -38,8 +38,7 @@ export async function resolveImportCard(
card: ImportCardPayload,
): Promise<ResolveResult> {
try {
- const user = await getCurrentUser();
- if (!user) throw new Error("Not authenticated");
+ const user = await requireUser();
// Verify resume ownership
const owned = await prisma.resume.findUnique({
diff --git a/src/components/tasks/tasks-container/useAutoOpenAddTaskDialog.ts b/src/components/tasks/tasks-container/useAutoOpenAddTaskDialog.ts
index ebfcd7a..e5122ff 100644
--- a/src/components/tasks/tasks-container/useAutoOpenAddTaskDialog.ts
+++ b/src/components/tasks/tasks-container/useAutoOpenAddTaskDialog.ts
@@ -23,5 +23,5 @@ export function useAutoOpenAddTaskDialog(
: window.location.pathname;
router.replace(newPath);
}
- }, [router, searchParams]);
+ }, [router, searchParams, setDialogOpen]);
}