Next.js Discord

Discord Forum

Data not showing in vercel

Unanswered
King Charles Spaniel posted this in #help-forum
Open in Discord
King Charles SpanielOP
With this code:

export const dynamic = 'force-dynamic';
import { PrismaClient } from "@prisma/client";
import NavbarForCaterers from "@/app/components/NavbarForCaterers";
import Footer from "@/app/components/Footer";
import QuoteTwo from "@/app/components/QuoteTwo";
import { currentUser } from "@clerk/nextjs";
import AreaCodeSelector from "@/app/components/AreaCodeSelector";
import { User } from "@clerk/nextjs/server";
const prisma = new PrismaClient();
import ClientSideScrollHandler from "@/app/components/ClientSideScrollHandler";
import { ExclamationTriangleIcon } from "@heroicons/react/20/solid";
import OnboardingUI from "@/app/components/OnboardingUI";

async function getData(user) {
'use server'
try {
const selectedPostCodes = (user?.unsafeMetadata?.selectedPostCodes || []) as {
code: string;
}[];
console.log("Selected Post Codes:", selectedPostCodes);

const res = await prisma.formData.findMany({
where: {
areaCode: {
in: selectedPostCodes.map((postCodeObj) => postCodeObj.code),
},
},
include: { unlockedUsers: true },
});
console.log("Fetched data first one:", res)
return res;
} catch (error) {
console.error("Error fetching data?:", error);
return [];
}
}

export default async function Dashboard() {
'use server'
const user = await currentUser();
const quotes = await getData(user);
const userID = user?.id;
console.log("Fetched quotes:", quotes);

// Check if user has selected an area code
const hasSelectedAreaCode = (user?.unsafeMetadata?.selectedPostCodes as any[])?.length > 0;

I'm able to log the data in development.

But once this is deployed to vercel the logs are empty with:

Selected Post Codes: []
Fetched data first one: []
Fetched quotes: []


I think its got something to do with caching/hydration and ive tried to put force-dynamic and 'use server'.

Any idea where I could be going wrong or what to try next?

2 Replies

European sprat
I don't think this is going to solve your issue but I wanted to point out you only add "use server" for server actions and server actions aren't intended for getting data but for mutating data