-
Notifications
You must be signed in to change notification settings - Fork 32
Description
Prerequisites
- I have searched the repository’s issues and Kinde community to ensure my issue isn’t a duplicate
- I have checked the latest version of the library to replicate my issue
- I have read the contributing guidelines
- I agree to the terms within the code of conduct
Describe the issue
"@kinde-oss/kinde-auth-nextjs": "^2.4.6",
"next": "15.1.6",
In NextJS v15 the way a route is determined to be static or not is by awaiting either a header or params... (I originally thought it was just if the function was async) I ran into an issue where I had a page component getting kinde user and this was moved to another file because i'm using the kinde id as the id in my db except for the kp_ part of the string
// src/lib/kinde.ts
import 'server-only'
import { getKindeServerSession } from '@kinde-oss/kinde-auth-nextjs/server'
import { redirect } from 'next/navigation'
const { getUser } = getKindeServerSession()
export const getKindeUser = async () =>
getUser().then(user => (user ? { ...user, id: user.id.replace('kp_', '') } : redirect('/api/auth/login')))When deployed (not in dev mode) I would get the error to many redirects. the issue I found was that it was redirecting me to sign in from the function getKindeUser (as opposed to the middleware). This was because during the build I believe this expression was evaluated and user was null thus returning the redirect. when I looked at the build logs it said the pages using this function were static the only ones that were not static that were using this function were dynamic routes. I believe a fix can be to make getKindeServerSession an async function and just call await headers() to force it not to be evaluated at build.
Library URL
https://github.com/kinde-oss/kinde-auth-nextjs
Library version
2.4.6
Operating system(s)
macOS
Operating system version(s)
macOS sequoia Version 15.1.1
Further environment details
No response
Reproducible test case URL
No response
Additional information
No response