#issues with next build, kinde auth and prisma

12 messages · Page 1 of 1 (latest)

brave gale
#

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

twin sorrelBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

zinc lance
brave gale
zinc lance
#

btw, if the page is depended on session, it should be a dynamic page

brave gale
#

so maybe a force-dynamic ? but if every site needs to be authenticated isnt the whole app going to be dynamic o-o

zinc lance
brave gale
zinc lance
#

yeah

brave gale
#

generateStaticParmams is for /[id] pages with dynamic segments i guess that wouldnt apply here since mine is just a /journal page