Skip to content

Commit a31f069

Browse files
author
[bot]
committed
version 2.0.0-next.174
1 parent 3a727a9 commit a31f069

File tree

2 files changed

+8
-17
lines changed

2 files changed

+8
-17
lines changed

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
},
2424
"type": "module",
2525
"dependencies": {
26-
"@fontsource/fira-mono": "^4.5.0",
27-
"cookie": "^0.4.1"
26+
"@fontsource/fira-mono": "^4.5.0"
2827
}
2928
}

src/hooks.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,15 @@
1-
import * as cookie from 'cookie';
2-
31
/** @type {import('@sveltejs/kit').Handle} */
42
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');
94

10-
if (!cookies['userid']) {
5+
if (!userid) {
116
// if this is the first time the user has visited this app,
127
// 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: '/' });
2010
}
2111

22-
return response;
12+
event.locals.userid = userid;
13+
14+
return resolve(event);
2315
};

0 commit comments

Comments
 (0)