File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1
1
import type { EventHandler } from "$lib/types/handler.js" ;
2
2
3
3
export async function sessionHooks ( { event } : { event : EventHandler } ) {
4
+ const TWENTY_NINE_DAYS = 29 * 24 * 60 * 60 ; // 29 days in seconds
5
+
4
6
event . request . setSessionItem = async (
5
7
itemKey : string ,
6
8
itemValue : unknown ,
@@ -16,6 +18,7 @@ export async function sessionHooks({ event }: { event: EventHandler }) {
16
18
secure : process . env . NODE_ENV === "production" ,
17
19
sameSite : "lax" ,
18
20
httpOnly : true ,
21
+ maxAge : TWENTY_NINE_DAYS ,
19
22
} ,
20
23
) ;
21
24
} ;
Original file line number Diff line number Diff line change @@ -154,4 +154,35 @@ describe("sessionHooks", () => {
154
154
expect ( retrievedValue1 ) . toBeUndefined ( ) ;
155
155
expect ( retrievedValue2 ) . toBeUndefined ( ) ;
156
156
} ) ;
157
+
158
+ it ( "should set cookies with 29-day expiry" , async ( ) => {
159
+ // Arrange
160
+ const TWENTY_NINE_DAYS = 29 * 24 * 60 * 60 ; // 29 days in seconds
161
+ const event = {
162
+ request : { } ,
163
+ cookies : {
164
+ set : vi . fn ( ) ,
165
+ get : vi . fn ( ) ,
166
+ } ,
167
+ } ;
168
+
169
+ await sessionHooks ( { event } ) ;
170
+
171
+ // Act
172
+ await event . request . setSessionItem ( "testKey" , "testValue" ) ;
173
+
174
+ // Assert
175
+ expect ( event . cookies . set ) . toHaveBeenCalledWith (
176
+ "kinde_testKey" ,
177
+ "testValue" ,
178
+ expect . objectContaining ( {
179
+ maxAge : TWENTY_NINE_DAYS ,
180
+ domain : process . env . KINDE_COOKIE_DOMAIN ,
181
+ path : "/" ,
182
+ secure : process . env . NODE_ENV === "production" ,
183
+ sameSite : "lax" ,
184
+ httpOnly : true ,
185
+ } ) ,
186
+ ) ;
187
+ } ) ;
157
188
} ) ;
You can’t perform that action at this time.
0 commit comments