Mael Halna
KKinde
•Created by Mael Halna on 5/7/2025 in #💻┃support
Intermittent Next.js Auth Errors: "No response returned", "State not found", "Refresh failed"
Logs I was able to retrieve using Kinde debug mode directly in prod:
for the kinde_callback problem:
callback Error: Authentication flow: Received: 8cf8e6242f05854649e6e2d0e8e5 | Expected: State not found
at AuthorizationCode.<anonymous> (/var/task/apps//.next/server/chunks/2352.js:1:326905)
at /var/task/apps//.next/server/chunks/2352.js:1:324597
at Object.next (/var/task/apps/wedding-fr/.next/server/chunks/2352.js:1:324702)
at fulfilled (/var/task/apps//.next/server/chunks/2352.js:1:323358)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
For the setup error:
validateToken: token is valid - it will expire in -1549808.5529999733 seconds
validateToken: token is valid - it will expire in -1632608.5539999008 seconds
setup: access or id token expired - attempting refresh
setup: refresh tokens failed - returning error
the new error that I never had before (500) on api/auth/login:
⨯ Error: No response is returned from route handler '/vercel/path0/apps//src/app/api/auth/[kindeAuth]/route.ts'. Ensure you return a Response or a NextResponse in all branches of your handler.
at /var/task/node_modules/.pnpm/[email protected][email protected][email protected][email protected]/node_modules/next/dist/compiled/next-server/app-route.runtime.prod.js:14:39875
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
7 replies
KKinde
•Created by Mael Halna on 5/7/2025 in #💻┃support
Intermittent Next.js Auth Errors: "No response returned", "State not found", "Refresh failed"
About the POST handler – I've added that to app/api/auth/[kindeAuth]/route.ts. Quick question though, I didn't see this in the Kinde docs, is this a general new requirement?
Now, for the callback redirect (KINDE_POST_LOGIN_REDIRECT_URL):
You said to make the KINDE_POST_LOGIN_REDIRECT_URL env var point to /api/auth/kinde_callback itself. But wouldn't that just create an infinite loop? handleAuth() would finish, then redirect back to itself, right?
And then, how would I do your next step: "Then, after handleAuth() completes, redirect users from there to your custom /auth-callback page."? My custom /auth-callback page is where I do my DB user stuff, and that's what my KINDE_POST_LOGIN_REDIRECT_URL env var currently points to. So, how do I get from Kinde's callback to my own /auth-callback page if the env var is supposed to point back to Kinde's callback?
Regarding the cookies & client secret:
Checked the cookies again – SameSite=Lax, Secure=true, domain/path all look fine.
Confirmed KINDE_CLIENT_SECRET again too.
I've deployed the POST handler change. Really need to understand that redirect flow for KINDE_POST_LOGIN_REDIRECT_URL though.
7 replies