Skip to content

Commit 5e85866

Browse files
committed
fix(notifications): migrate API routes to new auth architecture
Replace getServerSession(AuthOptions) + manual permission checks with withAuthPermission / withAuth from lib/protectedRoute: - create: withAuthPermission({ resource: notification, action: write }) also removes unnecessary getUserById DB call - get: withAuth (session-only check) - read: withAuth (session-only check) Signed-off-by: Anotherdev <joseluismanco37@gmail.com>
1 parent 0a7db12 commit 5e85866

30 files changed

Lines changed: 131 additions & 199 deletions

File tree

app/(home)/events/[id]/evaluate/page.tsx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { redirect } from "next/navigation";
22
import { getAuthSession } from "@/lib/auth/authSession";
33
import { prisma } from "@/prisma/prisma";
4-
import {
5-
canEvaluateHackathon,
6-
canManageEvaluationPhase,
7-
canManageHackathonJudges,
8-
} from "@/lib/auth/permissions";
94
import { stripEvaluationsForViewer } from "@/lib/hackathons/evaluation-phase";
105
import { canEvaluateHackathon, hasPermission } from "@/lib/auth/roles";
116
import { HackathonEvaluateDashboard } from "@/components/evaluate/HackathonEvaluateDashboard";
@@ -90,7 +85,7 @@ export default async function HackathonEvaluatePage({
9085
});
9186

9287
const viewerId = session!.user!.id;
93-
const isDevrel = canManageHackathonJudges(session);
88+
const isDevrel = hasPermission(session?.user?.custom_attributes, { resource: "platform", action: "admin" });
9489

9590
// Rejected projects must never reach the client for non-devrel users — filter server-side.
9691
const visibleProjects = isDevrel

app/api/admin/ecosystem-careers/listings/[id]/approve/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { prisma } from '@/prisma/prisma';
4-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
4+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
55

66
// Per-listing approval for ingested external/getro rows. Community listings
77
// go through the project-level approve route; ingested listings get their
88
// own button per row because we can't bulk-approve an unknown company.
9-
export const POST = withAuthRole<RouteParams<{ id: string }>>(
10-
'devrel',
9+
export const POST = withAuthPermission<RouteParams<{ id: string }>>(
10+
{ resource: 'platform', action: 'admin' },
1111
async (_req, ctx) => {
1212
const { id } = await ctx.params;
1313
const listing = await prisma.jobListing.findUnique({

app/api/admin/ecosystem-careers/listings/[id]/patch/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { z } from 'zod';
44
import { prisma } from '@/prisma/prisma';
5-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
5+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
66

77
const patchSchema = z.object({
88
title: z.string().min(2).max(160).optional(),
99
company_logo: z.string().url().or(z.literal('')).nullable().optional(),
1010
});
1111

12-
export const PATCH = withAuthRole<RouteParams<{ id: string }>>(
13-
'devrel',
12+
export const PATCH = withAuthPermission<RouteParams<{ id: string }>>(
13+
{ resource: 'platform', action: 'admin' },
1414
async (req, ctx) => {
1515
const { id } = await ctx.params;
1616

app/api/admin/ecosystem-careers/listings/[id]/reject/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { prisma } from '@/prisma/prisma';
4-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
4+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
55

6-
export const POST = withAuthRole<RouteParams<{ id: string }>>(
7-
'devrel',
6+
export const POST = withAuthPermission<RouteParams<{ id: string }>>(
7+
{ resource: 'platform', action: 'admin' },
88
async (_req, ctx) => {
99
const { id } = await ctx.params;
1010
const listing = await prisma.jobListing.findUnique({

app/api/admin/ecosystem-careers/listings/[id]/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { prisma } from '@/prisma/prisma';
4-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
4+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
55

6-
export const DELETE = withAuthRole<RouteParams<{ id: string }>>(
7-
'devrel',
6+
export const DELETE = withAuthPermission<RouteParams<{ id: string }>>(
7+
{ resource: 'platform', action: 'admin' },
88
async (_req, ctx) => {
99
const { id } = await ctx.params;
1010
const listing = await prisma.jobListing.findUnique({

app/api/admin/ecosystem-careers/projects/[id]/approve/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
3-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
3+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
44
import { approveProjectForCareers } from '@/server/services/ecosystemCareers/submitListing';
55

6-
export const POST = withAuthRole<RouteParams<{ id: string }>>(
7-
'devrel',
6+
export const POST = withAuthPermission<RouteParams<{ id: string }>>(
7+
{ resource: 'platform', action: 'admin' },
88
async (_req, ctx) => {
99
const { id } = await ctx.params;
1010
try {

app/api/admin/ecosystem-careers/projects/[id]/pending/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { prisma } from '@/prisma/prisma';
4-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
4+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
55

6-
export const DELETE = withAuthRole<RouteParams<{ id: string }>>(
7-
'devrel',
6+
export const DELETE = withAuthPermission<RouteParams<{ id: string }>>(
7+
{ resource: 'platform', action: 'admin' },
88
async (_req, ctx) => {
99
const { id } = await ctx.params;
1010
const project = await prisma.project.findUnique({

app/api/admin/ecosystem-careers/projects/[id]/reject/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { NextResponse } from 'next/server';
22
import { revalidatePath } from 'next/cache';
33
import { prisma } from '@/prisma/prisma';
4-
import { withAuthRole, type RouteParams } from '@/lib/protectedRoute';
4+
import { withAuthPermission, type RouteParams } from '@/lib/protectedRoute';
55

6-
export const POST = withAuthRole<RouteParams<{ id: string }>>(
7-
'devrel',
6+
export const POST = withAuthPermission<RouteParams<{ id: string }>>(
7+
{ resource: 'platform', action: 'admin' },
88
async (_req, ctx) => {
99
const { id } = await ctx.params;
1010
const project = await prisma.project.findUnique({

app/api/events/[id]/evaluation-phase/route.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
22
import { HackathonEvaluationPhase } from "@prisma/client";
33
import { prisma } from "@/prisma/prisma";
44
import { getAuthSession } from "@/lib/auth/authSession";
5-
import {
6-
canEvaluateHackathon,
7-
canManageEvaluationPhase,
8-
} from "@/lib/auth/permissions";
5+
import { canEvaluateHackathon, hasPermission } from "@/lib/auth/roles";
96
import type { RouteParams } from "@/lib/protectedRoute";
107

118
type Params = RouteParams<{ id: string }>;
@@ -62,7 +59,7 @@ export async function POST(_request: NextRequest, context: Params) {
6259
if (!session?.user) {
6360
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
6461
}
65-
if (!canManageEvaluationPhase(session)) {
62+
if (!hasPermission(session.user?.custom_attributes, { resource: "event", action: "manage" })) {
6663
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
6764
}
6865

app/api/events/[id]/projects/route.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { NextRequest, NextResponse } from "next/server";
22
import { prisma } from "@/prisma/prisma";
33
import { getAuthSession } from "@/lib/auth/authSession";
4-
import {
5-
canEvaluateHackathon,
6-
verifyHackathonProjectsApiKey,
7-
} from "@/lib/auth/permissions";
84
import { stripEvaluationsForViewer } from "@/lib/hackathons/evaluation-phase";
95
import { canEvaluateHackathon } from "@/lib/auth/roles";
106
import { timingSafeEqual } from "node:crypto";

0 commit comments

Comments
 (0)