huggi / src /hooks.server.ts
coyotte508's picture
coyotte508 HF staff
🐛 Fix convos in spaces
fff76f9
raw
history blame
653 Bytes
import { dev } from "$app/environment";
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: "/",
// So that it works inside the space's iframe
sameSite: "none",
secure: !dev,
httpOnly: true,
expires: addYears(new Date(), 1),
});
const response = await resolve(event);
return response;
};