kinde-oss / kinde-auth-nextjs

Kinde NextJS SDK - authentication for server rendered apps
https://docs.kinde.com/developer-tools/sdks/backend/nextjs-sdk/
MIT License
157 stars 24 forks source link

Bug: isReturnToCurrentPage middleware setting #188

Closed gitdagray closed 4 months ago

gitdagray commented 4 months ago

Prerequisites

Describe the issue

I'm using "@kinde-oss/kinde-auth-nextjs": "^2.3.3" and "next": "^14.2.3",

My middleware:

export default function middleware(req: NextRequest) {
  return withAuth(req, {
    isReturnToCurrentPage: true,
  });
}

Expected Behavior:

I can see the GET request go through with this URL: /api/auth/login?post_login_redirect_url=/books/scifi

But Next.js gives this error: ⨯ Error: URL is malformed "/books/scifi". Please use only absolute URLs

I can confirm that rolling back to "@kinde-oss/kinde-auth-nextjs": "^2.2.10", eliminates the issue.

It is possible that this merged PR https://github.com/kinde-oss/kinde-auth-nextjs/pull/173 is the issue.

Another post on your Discord on 6/12/24 with the same issue identified this PR and said, "I'm suspecting it's due to recently merged PR which switched to using NextResponse.redirect() but it's not calling it correctly (i.e. by feeding it / instead of instance of req.nextUrl.clone() et. al. )"

Library URL

https://github.com/kinde-oss/kinde-auth-nextjs

Library version

2.3.3

Operating system(s)

Windows

Operating system version(s)

Windows 10 Pro

Further environment details

No response

Reproducible test case URL

No response

Additional information

This likely impacts anything above 2.2.10

tak0m0 commented 4 months ago

I am facing exactly the same problem. However, in my case, the problem still occurs in version 2.2.10. Explicitly setting isReturnToCurrentPage to false solves the problem, but it is not a fundamental solution.

DanielRivers commented 4 months ago

Hi @gitdagray and @tak0m0,

This has been fixed in https://github.com/kinde-oss/kinde-auth-nextjs/releases/tag/v2.3.5

tak0m0 commented 4 months ago

Sounds good!!! thanks!!!