Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: using getKindeServerSession doesn't trigger ssr on demand #261

Open
4 tasks done
yyaskriloff opened this issue Jan 22, 2025 · 1 comment · May be fixed by #262
Open
4 tasks done

Bug: using getKindeServerSession doesn't trigger ssr on demand #261

yyaskriloff opened this issue Jan 22, 2025 · 1 comment · May be fixed by #262
Labels
bug Something isn't working

Comments

@yyaskriloff
Copy link
Contributor

yyaskriloff commented Jan 22, 2025

Prerequisites

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

@yyaskriloff yyaskriloff added the bug Something isn't working label Jan 22, 2025
@yyaskriloff
Copy link
Contributor Author

I fixed this behavior by just calling await headers() inside getKindeUser. after all pages using this function were switched to non static at build

@yyaskriloff yyaskriloff linked a pull request Jan 22, 2025 that will close this issue
2 tasks
@DanielRivers DanielRivers linked a pull request Jan 23, 2025 that will close this issue
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant