Hello, it has been a while since I've used Next.js, and I can't seem to figure out what I am doing wrong or how to approach this flow. Whenever, I build my application I get the following issue.
Creating an optimized production build ...
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
Generating static pages (0/8) [ ]Error: User not found
at o (.../.next/server/app/(main)/journal/page.js:1:3557)
Error: User not found
at o (.../.next/server/app/(main)/journal/page.js:1:3557)
Error occurred prerendering page "/journal". Read more: https://nextjs.org/docs/messages/prerender-error
Error: User not found
at o (.../.next/server/app/(main)/journal/page.js:1:3557)
✓ Generating static pages (8/8)
> Export encountered errors on following paths:
/(main)/journal/page: /journal
page in question
import { RecordCard } from "@/components/record-card"
import { getUserIdFromKindeId } from "@/lib/auth"
import prisma from "@/lib/prisma"
export default async function JournalPage() {
const { id: userId } = await getUserIdFromKindeId();
const records = await prisma.journalRecord.findMany({
where: { userId }
});
return (
<>
{records.map((record) => (
<RecordCard key={record.id} record={record} />
))}
</>
);
}
import "server-only"
import { getKindeServerSession } from "@kinde-oss/kinde-auth-nextjs/server"
import prisma from "@/lib/prisma"
import { redirect } from "next/navigation"
export async function getUserIdFromKindeId() {
const { getUser } = getKindeServerSession();
const kindeUser = await getUser();
if (!kindeUser) redirect("/login");
const user = await prisma.user.findUniqueOrThrow({
where: {
kindeId: kindeUser?.id,
}
});
return user;
}
i have tried throwing if statements here and there but the build still fails. my middleware should also make sure kindeUser is present in these pages