fix: support async searchParams for Next.js 16 and bypass locking for admin users

This commit is contained in:
2026-07-08 11:38:15 +03:00
parent fe6bb264b0
commit 9edf6ac794
5 changed files with 17 additions and 12 deletions
+2 -1
View File
@@ -14,5 +14,6 @@ export async function GET(_: Request, context: { params: Promise<{ id: string }>
}); });
if (!ad) return NextResponse.json({ error: "NOT_FOUND" }, { status: 404 }); if (!ad) return NextResponse.json({ error: "NOT_FOUND" }, { status: 404 });
const plan = planFromUser(user as any); const plan = planFromUser(user as any);
return NextResponse.json({ data: maskAdForPlan(ad as any, plan?.code) }); const isAdmin = user.role === "ADMIN";
return NextResponse.json({ data: maskAdForPlan(ad as any, plan?.code, isAdmin) });
} }
+2 -1
View File
@@ -79,7 +79,8 @@ export async function GET(req: Request) {
thumbnailUrl: ad.creatives[0]?.thumbnailUrl || ad.creatives[0]?.url, thumbnailUrl: ad.creatives[0]?.thumbnailUrl || ad.creatives[0]?.url,
isSaved: savedIds.has(ad.id) isSaved: savedIds.has(ad.id)
}, },
plan?.code plan?.code,
user.role === "ADMIN"
) )
); );
+7 -5
View File
@@ -6,18 +6,20 @@ import { maskAdForPlan } from "@/lib/locked-response";
import { planFromUser } from "@/lib/plans"; import { planFromUser } from "@/lib/plans";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
export default async function AdsPage({ searchParams }: { searchParams: Record<string, string | undefined> }) { export default async function AdsPage({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
const user = await requireUser(); const user = await requireUser();
const plan = planFromUser(user as any); const plan = planFromUser(user as any);
const q = searchParams.q?.trim(); const resolvedSearchParams = await searchParams;
const niche = searchParams.niche; const q = resolvedSearchParams.q?.trim();
const mediaType = searchParams.mediaType; const niche = resolvedSearchParams.niche;
const mediaType = resolvedSearchParams.mediaType;
const where: Prisma.AdWhereInput = {}; const where: Prisma.AdWhereInput = {};
if (q) where.OR = [{ primaryText: { contains: q, mode: "insensitive" } }, { headline: { contains: q, mode: "insensitive" } }, { brandPage: { name: { contains: q, mode: "insensitive" } } }]; if (q) where.OR = [{ primaryText: { contains: q, mode: "insensitive" } }, { headline: { contains: q, mode: "insensitive" } }, { brandPage: { name: { contains: q, mode: "insensitive" } } }];
if (niche) where.niche = niche; if (niche) where.niche = niche;
if (mediaType) where.mediaType = mediaType as any; if (mediaType) where.mediaType = mediaType as any;
const ads = await prisma.ad.findMany({ where, include: { brandPage: true, creatives: { take: 1 }, savedBy: { where: { userId: user.id } } }, orderBy: { rankPercentile: "asc" }, take: 48 }); const ads = await prisma.ad.findMany({ where, include: { brandPage: true, creatives: { take: 1 }, savedBy: { where: { userId: user.id } } }, orderBy: { rankPercentile: "asc" }, take: 48 });
const masked = ads.map((ad) => maskAdForPlan({ ...ad, isSaved: ad.savedBy.length > 0 }, plan?.code)); const isAdmin = user.role === "ADMIN";
const masked = ads.map((ad) => maskAdForPlan({ ...ad, isSaved: ad.savedBy.length > 0 }, plan?.code, isAdmin));
return ( return (
<div> <div>
+4 -3
View File
@@ -4,10 +4,11 @@ import { prisma } from "@/lib/db";
import { requireUser } from "@/lib/auth/current-user"; import { requireUser } from "@/lib/auth/current-user";
import { Card } from "@/components/ui/card"; import { Card } from "@/components/ui/card";
export default async function StoresPage({ searchParams }: { searchParams: Record<string, string | undefined> }) { export default async function StoresPage({ searchParams }: { searchParams: Promise<Record<string, string | undefined>> }) {
await requireUser(); await requireUser();
const q = searchParams.q?.trim(); const resolvedSearchParams = await searchParams;
const niche = searchParams.niche; const q = resolvedSearchParams.q?.trim();
const niche = resolvedSearchParams.niche;
const where: Prisma.StoreWhereInput = {}; const where: Prisma.StoreWhereInput = {};
if (q) where.OR = [{ name: { contains: q, mode: "insensitive" } }, { domain: { contains: q, mode: "insensitive" } }]; if (q) where.OR = [{ name: { contains: q, mode: "insensitive" } }, { domain: { contains: q, mode: "insensitive" } }];
if (niche) where.niche = niche; if (niche) where.niche = niche;
+2 -2
View File
@@ -1,7 +1,7 @@
import { PlanCode } from "@prisma/client"; import { PlanCode } from "@prisma/client";
export function maskAdForPlan<T extends Record<string, any>>(ad: T, planCode?: PlanCode): T & { isLocked: boolean } { export function maskAdForPlan<T extends Record<string, any>>(ad: T, planCode?: PlanCode, bypassLock?: boolean): T & { isLocked: boolean } {
if (planCode && planCode !== "FREE") return { ...ad, isLocked: false }; if (bypassLock || (planCode && planCode !== "FREE")) return { ...ad, isLocked: false };
return { return {
...ad, ...ad,
primaryText: ad.primaryText ? `${String(ad.primaryText).slice(0, 90)}...` : null, primaryText: ad.primaryText ? `${String(ad.primaryText).slice(0, 90)}...` : null,