File tree Expand file tree Collapse file tree 2 files changed +8
-17
lines changed Expand file tree Collapse file tree 2 files changed +8
-17
lines changed Original file line number Diff line number Diff line change 23
23
},
24
24
"type" : " module" ,
25
25
"dependencies" : {
26
- "@fontsource/fira-mono" : " ^4.5.0" ,
27
- "cookie" : " ^0.4.1"
26
+ "@fontsource/fira-mono" : " ^4.5.0"
28
27
}
29
28
}
Original file line number Diff line number Diff line change 1
- import * as cookie from 'cookie' ;
2
-
3
1
/** @type {import('@sveltejs/kit').Handle } */
4
2
export const handle = async ( { event, resolve } ) => {
5
- const cookies = cookie . parse ( event . request . headers . get ( 'cookie' ) || '' ) ;
6
- event . locals . userid = cookies [ 'userid' ] || crypto . randomUUID ( ) ;
7
-
8
- const response = await resolve ( event ) ;
3
+ let userid = event . cookies . get ( 'userid' ) ;
9
4
10
- if ( ! cookies [ ' userid' ] ) {
5
+ if ( ! userid ) {
11
6
// if this is the first time the user has visited this app,
12
7
// set a cookie so that we recognise them when they return
13
- response . headers . set (
14
- 'set-cookie' ,
15
- cookie . serialize ( 'userid' , event . locals . userid , {
16
- path : '/' ,
17
- httpOnly : true
18
- } )
19
- ) ;
8
+ userid = crypto . randomUUID ( ) ;
9
+ event . cookies . set ( 'userid' , userid , { path : '/' } ) ;
20
10
}
21
11
22
- return response ;
12
+ event . locals . userid = userid ;
13
+
14
+ return resolve ( event ) ;
23
15
} ;
You can’t perform that action at this time.
0 commit comments