Cached data served to the wrong user
NEXTAI-01unstable_cache reads the signed-in user from the surrounding scope but keys the cache without it, so one user's data is served to everyone.
app/dashboard/orders/page.tsx
Flagged
import { unstable_cache } from 'next/cache';
import { auth } from '@/auth';
import { db } from '@/lib/db';
export default async function OrdersPage() {
const userId = (await auth())?.user?.id;
const getOrders = unstable_cache(
async () => db.order.findMany({ where: { userId } }),
['dashboard-orders']
);
return <OrderList orders={await getOrders()} />;
}
Passes
import { unstable_cache } from 'next/cache';
import { auth } from '@/auth';
import { db } from '@/lib/db';
const getOrders = unstable_cache(
async (userId: string) => db.order.findMany({ where: { userId } }),
['dashboard-orders']
);
export default async function OrdersPage() {
const userId = (await auth())?.user?.id;
return <OrderList orders={await getOrders(userId!)} />;
}