Closed abdus closed 2 months ago
I'm seeing the same error on Vercel, but not on local.
My temp bandaid is to auto retry when that failure happens. The user will only experience a little delay.
// Submit and get response message
let attempts = 0
let responseMessage: any = null
while (attempts < 3) {
try {
responseMessage = await submitUserMessage(value)
if (responseMessage) {
setMessages(currentMessages => [...currentMessages, responseMessage])
}
break // Exit loop on success
} catch (error) {
console.error(`Attempt ${attempts + 1} failed:`, error)
attempts++
if (attempts === 3) {
console.error('Failed to submit user message after 3 attempts.')
}
}
}
were you able to solve this? I'm having the same problem.
This is pretty late but I was having the same issue as I was migrating a project to RSCs and managed to fix it.
The problem for me was the auth check in the middleware, to redirect to the login page if the request came from a user that wasn't logged in, and that was conflicting with the server action request, causing the error.
Fixed it by adding a check to see if the "Accept" field in the header is for a component.
import { auth } from '@/auth'
import { NextResponse } from 'next/server'
// More on how NextAuth.js middleware works: https://authjs.dev/getting-started/migrating-to-v5#details
export default auth(req => {
const url = new URL('/login', req.url)
const acceptHeader = req.headers.get('accept')
// Allow requests for Server Actions and Server Components
if (acceptHeader && acceptHeader.includes('text/x-component')) {
return NextResponse.next()
}
// Redirect to login page if user is not authenticated
if (!req.auth?.user) {
return !req.nextUrl.pathname.includes('/login') // Prevent infinite redirect loop
? NextResponse.redirect(url)
: NextResponse.next()
}
return NextResponse.next()
})
export const config = {
matcher: ['/((?!api|_next/static|favicon|_next/image||.*\\.png$).*)']
}
Any update on this? Today I run my repo in local and encountered this exact issue and couldn't figure out how to debug it. A couple days before it was still fine. On production it's still fine. But for some reason, the issue suddenly appeared. Any help please?
Hey! Did you by chance update all of the dependencies? Can you check what version of next-auth
you are using?
I tried to reproduce and got this error after running pnpm up --latest
. This command ended up downgrading my next-auth
version from 5.0.0-beta.4 to 4.24.7. I ran pnpm install next-auth@beta
and it resolved all the issues.
Let me know if that resolves the problem for you.
Please report back if this is still an issue
If you're looking into this issue, you might find this helpful:
https://github.com/vercel/next.js/discussions/64993
It seems like middleware redirects have been disabled for server actions - so if you want to authenticate a server action, you'll need to do that inside the action.
Description
I am using Next.js AI Chatbot template. Every time I try to create a new thread by sending a message caused the above-mentioned error. Now, I narrowed down the error using
debugger
, but still unable to fix it.Code example
File: rsc/shared-client/context.tsx
My Component Looks like this:
Application-level Error Message:
Additional context
I have been trying to fix this issue since last week. Any help is appreciated. Thank you in advance.