Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/api/newsletter/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
import { auth, clerkClient } from "@clerk/nextjs/server";
import { PrismaClient } from "@prisma/client";
import { upstashLimit } from "@/lib/rate-limit-upstash";
import { getClientIP } from "@/lib/rate-limit";
Expand Down Expand Up @@ -208,8 +208,19 @@
}

// GET /api/newsletter/stats - Get newsletter statistics (admin only)
export async function GET(request: NextRequest) {
export async function GET(_request: NextRequest) {

Check warning on line 211 in app/api/newsletter/route.ts

View workflow job for this annotation

GitHub Actions / build

'_request' is defined but never used
try {
const { userId } = await auth();

if (!userId) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
Comment on lines +213 to +217

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restrict newsletter stats to admins

For any regular signed-in Clerk user, this check only verifies that auth() returned a userId, so GET /api/newsletter still returns recentSubscribers with subscriber emails/names/sources. Since this handler is marked admin-only and sign-up is public in the app, the sensitive subscriber list remains exposed to all authenticated users unless you also validate an admin role/metadata or move it behind an admin-only route.

Useful? React with 👍 / 👎.


const user = await clerkClient.users.getUser(userId);
if (user.publicMetadata?.role !== "admin") {
return NextResponse.json({ error: "Forbidden" }, { status: 403 });
}

const totalSubscribers = await prisma.newsletterSubscriber.count({
where: { status: "active" },
});
Expand Down
Loading