NextJS App Router Error out in middleware
Hello,
I've been working on implementing Kinde Auth within the Next.js app router using middleware. However, I encountered an error after logging in.
Code -
Additionally, I have a backend server where I aim to authenticate requests originating from the client-side Next.js application. Do I need to register a new application on the dashboard? Also, is there a method to authenticate these requests on the server? (The server is written in Nest.js.)
8 Replies
Thanks for providing all the details @Chetan Verma I will flick this over to our NextJS expert to help troubleshoot this. Are you using Kinde NextJS SDK v2.0.10?
I got the same error, and yes, I am using the Kinde NextJS SDK v2.0.10.
Got the same error.
https://discord.com/channels/1070212618549219328/1180581283659784242
Hi @Chetan Verma, @Peter Hu and @Ruyy,
We have identified an issue with the middleware in NextJS App Router v2.
You should be able to use the middleware in NextJS App Router v1: https://kinde.com/docs/developer-tools/nextjs-sdkv1/#protecting-pages
We will patch the middleware in NextJS App Router v2, but you should be able to continue using the middleware in NextJS App Router v1 before and after the patch to achieve what you are after.
Please let me know if you have any other questions.
I am here to help.
Kinde Docs
NextJS App Router SDK v1 - Developer tools - Help center
Our developer tools provide everything you need to get started with Kinde.
Thank you, Oli. I have a question unrelated to this middleware error (and still is a middleware question). What if I have a couple of public pages for the user? Do I need to modify the middleware to ignore Kinde authMiddleware and use the NextResponse.next()? Currently, it always redirects me back to the home page.
The middleware should only run when visiting a page/route included in the matcher. So if you don't want the middleware to run on a page, then you should make sure it's not covered by the matcher 🙂
With this error we are running into - when are we seeing it?
the
TypeError: Cannot read properties of undefined (reading value)
I'm tryng to see if I can recreate the issue so I might be able to fix itCurrently dealing with the same issue, the error begins when a user attempts to login/SignUp, they are redirected to the kinde auth page and after signing in they are sent back to the site This is where the error begins
It appears the user cookie is created and saved but when trying to access any private routes configured in middleware.ts the user is shown the error
Also forgot to mention when trying to access private routes the user is returned unauthorised, even tho they are and allowed to view it, the user is then redirected to /auth-callback and then the error is shown on the page
Hey @Chetan Verma, @Peter Hu, @Ruyy and @BigRIP,
There is a new version of the NextJS SDK v2.0.11 that fixed this middleware issue.
Please let us know if you are still experiencing any issues.