Next.js Build doesn't call getUser() from kinde

Hey all, Nextjs calls all of the requests in a file when running npm run build. This causes my requests to fire, but not kinde's getKindeServerSession() or getUser() functions. I'm trying to test my production build. I currently have Kinde set up to return a kinde object, which then sends a request to my backend to get the user object based on the kinde id. The issue I'm running into is the await getUser() returns null when I run npm run build on my nextJS project. This causes an error with the user on the backend (because null user does not exist), resulting in a 400 on the backend, which gets sent to the FE. Is this intentional? I don't know why this happens. I can prevent the build from failing with some if statements, so it's not a blocker. I'm curious if I'm misunderstanding something with nextjs entirely or if this is kinde specific.
No description
3 Replies
Gamer Guy
Gamer GuyOP2w ago
No description
Gamer Guy
Gamer GuyOP2w ago
This is specifically what's happening. USER 2 gets printed out in the console with null as the user Is there a reason for this? And should this be in the documentation somewhere? I figured. Thanks
Yoshify
Yoshify2w ago
Just to add further onto Sams comment - the reason this happens is because your page is being generated as a Static page (which means API requests, etc. are resolved and embedded statically in the page). If you have dynamic content on your page (such as user specific information) you should not be generating this statically. Next is normally pretty good at automatically detecting this, but in some cases you need to tell it what to do. You can manually opt into dynamic rendering (SSR) by adding the following within your route: export const dynamic = 'force-dynamic'; This should resolve the error entirely. If you want to stick with SSG however, you'll just need to ignore the null user entirely.
Want results from more Discord servers?
Add your server