kinde-oss/kinde-auth-nextjs

Bug: isReturnToCurrentPage middleware setting

Closed this issue · 3 comments

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:

  • Go directly to domain.com/books/scifi and get redirected to login ✅ Ok
  • After logging in, get redirected back to domain.com/books/scifi ❌Fails

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 #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

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.

Sounds good!!! thanks!!!