swift
swift
KKinde
Created by swift on 3/12/2025 in #💻┃support
Nextjs middleware post login redirect not working
• Framework: Next.js 14.2.21 • Auth Library: @kinde-oss/kinde-auth-nextjs v2.5.3 The middleware post login redirect fails (and I believe the token refresh fails too). When signed in and opening a page which is protected by the middleware I see the logs: authMiddleware: no access or id token, redirecting to login ⨯ TypeError: Invalid URL at new URL (node:internal/url:816:29) at eval (webpack-internal:///(rsc)/./node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js:23:55762) at eval (webpack-internal:///(rsc)/./node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js:23:12358) at Object.eval [as next] (webpack-internal:///(rsc)/./node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js:23:12463) at s (webpack-internal:///(rsc)/./node_modules/@kinde-oss/kinde-auth-nextjs/dist/server/index.js:23:11181) { code: 'ERR_INVALID_URL', input: 'http://localhost:3001', base: '/household' } And the URL shows: http://localhost:3001/api/auth/kinde_callback?code=..... When not signed in and opening a page protected by middleware, it directs me to the Kinde login page, I sign in, then the redirect fails with the same issue as above. I have also seen: authMiddleware: access token expired, refreshing authMiddleware: token refresh failed, redirecting to login And then the same redirect error. I think that means the postloginredirect is not working and the token refresh is failing with the same error. Without middleware and manually checking for tokens and using the kinde login and register components, the login and postloginredirect work without issue. Am I doing something wrong with the middleware or is this an issue on Kinde's side? (Attached extra information as text file due to too long message warning)
13 replies