boredgame/src/hooks.server..ts

17 lines
440 B
TypeScript
Raw Normal View History

2022-01-28 05:27:12 +00:00
import type { Handle } from '@sveltejs/kit';
export const handle: Handle = async ({ event, resolve }) => {
2022-09-29 22:22:01 +00:00
let userid = event.cookies.get('userid');
2022-01-28 05:27:12 +00:00
2022-09-29 22:22:01 +00:00
if (!userid) {
// if this is the first time the user has visited this app,
// set a cookie so that we recognise them when they return
userid = crypto.randomUUID();
event.cookies.set('userid', userid, { path: '/' });
}
2022-01-28 05:27:12 +00:00
2022-09-29 22:22:01 +00:00
event.locals.userid = userid;
2022-01-28 05:27:12 +00:00
2022-09-29 22:22:01 +00:00
return resolve(event);
2022-01-28 05:27:12 +00:00
};