chat-ui / src /hooks.server.ts
victor's picture
victor HF staff
Prettier update (#54)
5da61b4 unverified
raw
history blame
564 Bytes
import { COOKIE_NAME } from "$env/static/private";
import type { Handle } from "@sveltejs/kit";
import { addYears } from "date-fns";
export const handle: Handle = async ({ event, resolve }) => {
const token = event.cookies.get(COOKIE_NAME);
event.locals.sessionId = token || crypto.randomUUID();
// Refresh cookie expiration date
event.cookies.set(COOKIE_NAME, event.locals.sessionId, {
path: "/",
sameSite: "lax",
secure: true,
httpOnly: true,
expires: addYears(new Date(), 1),
});
const response = await resolve(event);
return response;
};