issues with next build, kinde auth and prisma
Unanswered
Abyssinian posted this in #help-forum
AbyssinianOP
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.
page in question
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
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: /journalpage 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
11 Replies
@Ray `console.log(kindeUser)`
try if you see the user object?
AbyssinianOP
its null
which I guess makes sense because the build doesnt have a session
[kindeUser from getUserIdFromKindeId] nullwhich I guess makes sense because the build doesnt have a session
@Abyssinian its null
[kindeUser from getUserIdFromKindeId] null
which I guess makes sense because the build doesnt have a session
I think you would need to use
generateStaticParams to pre-render those pagesbtw, if the page is depended on session, it should be a dynamic page
AbyssinianOP
so maybe a
force-dynamic ? but if every site needs to be authenticated isnt the whole app going to be dynamic o-o@Abyssinian so maybe a `force-dynamic` ? but if every site needs to be authenticated isnt the whole app going to be dynamic o-o
you could build the static page and use middleware for authentication
@Ray you could build the static page and use middleware for authentication
AbyssinianOP
i guess that pages that dont need the kindeUserId can stay static where if i need to use the kindeUser object ill have to make it dynamic
I do have middleware protecting routes
I do have middleware protecting routes
@Abyssinian i guess that pages that dont need the kindeUserId can stay static where if i need to use the kindeUser object ill have to make it dynamic
I do have middleware protecting routes
yeah or you can use
generateStaticParams and query all the user inside of ityeah
AbyssinianOP
generateStaticParmams is for
/[id] pages with dynamic segments i guess that wouldnt apply here since mine is just a /journal page