You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While working on #1634 I noticed that the path for the 'Cookies API' in demos/middleware/middleware.ts wasn't being reached where the netlifyCookie is set, and this behaviour is happening on the main branch.
This seems to happen for most of the routes listed within the middleware file (the first conditional - /static is working correctly however).
Determine why the behaviour within the middleware demo isn't working as expected, where the user is able to visit the routes (correctly) but some of the side effects of the middleware are not being run (like the setting of the cookie).
The text was updated successfully, but these errors were encountered:
In case it's related and helps debug here was my experience with cookies in middleware recently...
Could very likely be an implementation misunderstanding on my part, but I expected to receive the same cookies from the nextRequest when it was wrapped in MiddlewareRequest from @netlify/next as when it was bare, but when using ntl dev cookies cleared across routes with MiddlewareRequest but not with the bare nextRequest: NextRequest
The following code works but I've added a comment to show what I expected:
import type { NextRequest } from 'next/server'
import { MiddlewareRequest } from '@netlify/next'
export async function middleware(nextRequest: NextRequest) {
const middlewhereRequest = new MiddlewareRequest(nextRequest)
const response = await middlewhereRequest.next()
const pathName = nextRequest.nextUrl.pathname
const financialServices = 'financial-services'
const industry = 'industry'
if (pathName.includes(financialServices)) {
response.cookies.set(industry, financialServices)
}
if (nextRequest.cookies.get(industry) == financialServices) {
// I expected response.cookies.get(industry) to be the same as nextRequest.cookies.get(industry) but it cleared when I changed routes
const message = 'The best platform for financial services companies'
response.replaceText('#message', message)
response.setPageProp('message', message)
}
return response
}
While working on #1634 I noticed that the path for the 'Cookies API' in
demos/middleware/middleware.ts
wasn't being reached where thenetlifyCookie
is set, and this behaviour is happening on themain
branch.This seems to happen for most of the routes listed within the middleware file (the first conditional -
/static
is working correctly however).Determine why the behaviour within the middleware demo isn't working as expected, where the user is able to visit the routes (correctly) but some of the side effects of the middleware are not being run (like the setting of the cookie).
The text was updated successfully, but these errors were encountered: