Unable to retrieve authenticated user data
Hello , im making an next.js project with kinde , but when i want to retrieve authenticated user data in my route server component , it returns nnull
2 Replies
Hey Martin. Are you using middleware? This is required for the current version of Next.js.
Hi Martin—let’s gather a bit more info so we can pinpoint what’s going on with your
getKindeServerSession() call returning null:
1. Next.js version and App vs. Pages Router
- Which Next.js version are you on? (e.g. 13.x vs. 12.x)
- Are you using the new App Router (app/ directory) or the traditional Pages Router (pages/ directory)?
2. Middleware Setup
- Do you have a middleware.ts (or .js) file at your project root?
- If so, can you share its contents—especially the part where you import and configure Kinde’s middleware?
3. Kinde Provider & Config
- Have you wrapped your app in the <KindeProvider> (or equivalent) in your root layout?
- Are your environment variables (KINDE_CLIENT_ID, KINDE_ISSUER_BASE_URL, etc.) set and loading correctly in your server environment?
4. Route Context
- Where exactly are you calling getKindeServerSession()—inside app/dashboard/layout.tsx, page.tsx, or another route?
- Is that file a Server Component (default under app/), or did you add the "use client" directive by mistake?
5. Cookies & Headers
- When you inspect the request in Wokwi (or Postman), do you see the Kinde session cookie (e.g. __Secure-next-auth.session-token) being sent?
- Are you using any custom cookie settings (secure, sameSite, domain) that might prevent the cookie from reaching your route?
6. Error Details
- Do you see any warning or error logs when your app starts or when you hit the dashboard route?
- Does getUser() ever throw, or does it simply return null silently?
If you can share those details (code snippets or screenshots of your middleware.ts, env config, and how you’re wiring the provider), we’ll be able to zero in on what’s missing. Thanks