File tree Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Expand file tree Collapse file tree 1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import {
24
24
normalizeVisitorAuthURL ,
25
25
} from '@/lib/visitors' ;
26
26
import { serveResizedImage } from '@/routes/image' ;
27
+ import { cookies } from 'next/headers' ;
27
28
import type { SiteURLData } from './lib/context' ;
28
29
export const config = {
29
30
matcher : [
@@ -545,9 +546,16 @@ function appendQueryParams(url: URL, from: URLSearchParams) {
545
546
/**
546
547
* Write the cookies to a response.
547
548
*/
548
- function writeResponseCookies < R extends NextResponse > ( response : R , cookies : ResponseCookies ) : R {
549
- cookies . forEach ( ( cookie ) => {
550
- response . cookies . set ( cookie . name , cookie . value , cookie . options ) ;
549
+ async function writeResponseCookies < R extends NextResponse > (
550
+ response : R ,
551
+ cookiesToSet : ResponseCookies
552
+ ) : Promise < R > {
553
+ const cookiesFn = await cookies ( ) ;
554
+ cookiesToSet . forEach ( ( cookie ) => {
555
+ // response.cookies.set(cookie.name, cookie.value, cookie.options);
556
+ // For some reason we have to use the cookies function instead of response.cookies.set
557
+ // Without it, it breaks the ai assistant server actions (it thinks it is a static route).
558
+ cookiesFn . set ( cookie . name , cookie . value , cookie . options ) ;
551
559
} ) ;
552
560
553
561
return response ;
You can’t perform that action at this time.
0 commit comments