Skip to content

Commit a478d4d

Browse files
authored
fix(api): add admin authorization check to sponsor-ads routes (#423)
- Add isAdmin validation to all sponsor-ads admin API handlers - Return 403 Forbidden for non-admin users - Align with authorization pattern used in other admin routes
2 parents 040897c + 3cbb15d commit a478d4d

File tree

5 files changed

+42
-0
lines changed

5 files changed

+42
-0
lines changed

app/api/admin/sponsor-ads/[id]/approve/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ export async function POST(
5353
);
5454
}
5555

56+
if (!session.user.isAdmin) {
57+
return NextResponse.json(
58+
{ success: false, error: "Forbidden" },
59+
{ status: 403 }
60+
);
61+
}
62+
5663
const { id } = await params;
5764

5865
// Parse request body for forceApprove flag

app/api/admin/sponsor-ads/[id]/cancel/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ export async function POST(
6868
);
6969
}
7070

71+
if (!session.user.isAdmin) {
72+
return NextResponse.json(
73+
{ success: false, error: "Forbidden" },
74+
{ status: 403 }
75+
);
76+
}
77+
7178
const { id } = await params;
7279
const body = await request.json().catch(() => ({}));
7380

app/api/admin/sponsor-ads/[id]/reject/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ export async function POST(
7272
);
7373
}
7474

75+
if (!session.user.isAdmin) {
76+
return NextResponse.json(
77+
{ success: false, error: "Forbidden" },
78+
{ status: 403 }
79+
);
80+
}
81+
7582
const { id } = await params;
7683
const body = await request.json();
7784

app/api/admin/sponsor-ads/[id]/route.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ export async function GET(
4141
);
4242
}
4343

44+
if (!session.user.isAdmin) {
45+
return NextResponse.json(
46+
{ success: false, error: "Forbidden" },
47+
{ status: 403 }
48+
);
49+
}
50+
4451
const { id } = await params;
4552
const sponsorAd = await sponsorAdService.getSponsorAdWithUser(id);
4653

@@ -103,6 +110,13 @@ export async function DELETE(
103110
);
104111
}
105112

113+
if (!session.user.isAdmin) {
114+
return NextResponse.json(
115+
{ success: false, error: "Forbidden" },
116+
{ status: 403 }
117+
);
118+
}
119+
106120
const { id } = await params;
107121

108122
await sponsorAdService.deleteSponsorAd(id);

app/api/admin/sponsor-ads/route.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@ export async function GET(request: NextRequest) {
7070
);
7171
}
7272

73+
if (!session.user.isAdmin) {
74+
return NextResponse.json(
75+
{ success: false, error: "Forbidden" },
76+
{ status: 403 }
77+
);
78+
}
79+
7380
const { searchParams } = new URL(request.url);
7481

7582
// Validate pagination parameters

0 commit comments

Comments
 (0)