@@ -8,6 +8,14 @@ import { detectClerkMiddleware } from '../server/headers-utils';
88import { getKeylessCookieName , getKeylessCookieValue } from '../server/keyless' ;
99import { canUseKeyless } from '../utils/feature-flags' ;
1010
11+ type SetCookieOptions = Parameters < Awaited < ReturnType < typeof cookies > > [ 'set' ] > [ 2 ] ;
12+
13+ const keylessCookieConfig = {
14+ secure : false ,
15+ httpOnly : false ,
16+ sameSite : 'lax' ,
17+ } satisfies SetCookieOptions ;
18+
1119export async function syncKeylessConfigAction ( args : AccountlessApplication & { returnUrl : string } ) : Promise < void > {
1220 const { claimUrl, publishableKey, secretKey, returnUrl } = args ;
1321 const cookieStore = await cookies ( ) ;
@@ -22,10 +30,11 @@ export async function syncKeylessConfigAction(args: AccountlessApplication & { r
2230 }
2331
2432 // Set the new keys in the cookie.
25- cookieStore . set ( await getKeylessCookieName ( ) , JSON . stringify ( { claimUrl, publishableKey, secretKey } ) , {
26- secure : true ,
27- httpOnly : true ,
28- } ) ;
33+ cookieStore . set (
34+ await getKeylessCookieName ( ) ,
35+ JSON . stringify ( { claimUrl, publishableKey, secretKey } ) ,
36+ keylessCookieConfig ,
37+ ) ;
2938
3039 // We cannot import `NextRequest` due to a bundling issue with server actions in Next.js 13.
3140 // @ts -expect-error Request will work as well
@@ -63,11 +72,11 @@ export async function createOrReadKeylessAction(): Promise<null | Omit<Accountle
6372 } ) ;
6473
6574 const { claimUrl, publishableKey, secretKey, apiKeysUrl } = result ;
66-
67- void ( await cookies ( ) ) . set ( await getKeylessCookieName ( ) , JSON . stringify ( { claimUrl , publishableKey , secretKey } ) , {
68- secure : false ,
69- httpOnly : false ,
70- } ) ;
75+ void ( await cookies ( ) ) . set (
76+ await getKeylessCookieName ( ) ,
77+ JSON . stringify ( { claimUrl , publishableKey , secretKey } ) ,
78+ keylessCookieConfig ,
79+ ) ;
7180
7281 return {
7382 claimUrl,
0 commit comments