-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Next.js 14 Ensure you return a Response
or a NextResponse
in all branches of your handler.
#240
Comments
We have a suspect, that next-intl can potentially alter responses in a way the produces this error. For now it's just an unconfirmed assumption, but next-intl is what we added to the stack that was working smoothly earlier on. We also run into another issue with next-intl, maybe someone with more context will be able to connect those dots faster: |
I'm having this issue too.
This does Not work:
Yielding error:
▲ Next.js 14.0.4 |
This is how I used it before, and I also got this error. const router = createEdgeRouter<NextRequest, RequestContext>()
router
// A middleware example
.use(async (request, event, next) => {
const start = Date.now()
await next() // call next in chain
const end = Date.now()
console.log(`Request took ${end - start}ms`)
})
.get(async (request) => {
try {
return NextResponse.json([])
} catch (error: any) {
console.log('🚀 ~ GET ~ error:', error)
return NextResponse.json([])
}
})
export async function GET(request: NextRequest, ctx: RequestContext) {
return router.run(request, ctx)
} Later I changed it to const router = createEdgeRouter<NextRequest, RequestContext>()
router
// changed here
.use((request, event, next) => {
const start = Date.now()
const end = Date.now()
console.log(`Request took ${end - start}ms`)
return next()
})
.get(async (request) => {
try {
return NextResponse.json([])
} catch (error: any) {
console.log('🚀 ~ GET ~ error:', error)
return NextResponse.json([])
}
})
export async function GET(request: NextRequest, ctx: RequestContext) {
return router.run(request, ctx)
} Then it's ok |
Also works for me in Nextjs 14.1 while keeping the the first function async. |
Since we need to return
|
Here is the route handler implementation:
As you can see it's pretty simple GET endpoint. For simplicity, I removed the GET related logic, as it seems it doesn't have anything to do with the problem.
Currently, when I am redirected from my auth form (Supabase Auth) to the
http://localhost:3000/api/v1/auth/callback?code=some-random-values
I get the following error:Which is odd, as I consider
return NextResponse.redirect(origin)
a valid response 🤔Here is the request object to provide more context:
Middlewares are pretty straightforward as well:
It's my attempt to convert my route to next-connect structure, it seems to me it's some sort of an issue with next-connect. However I am not next-connect heavy user, so messing smth up is also an option. It is however my 2nd issue with next-connect while working with the newest next.js 14. While working with older versions I didn't have issues like that.
Here is my regular route, that works without any issues:
The text was updated successfully, but these errors were encountered: