diff --git a/app/components/common/Toggle.tsx b/app/components/common/Toggle.tsx index 22eb730..31f5b6e 100644 --- a/app/components/common/Toggle.tsx +++ b/app/components/common/Toggle.tsx @@ -26,7 +26,7 @@ export function Toggle(props: ToggleProps) { { - setConsentCookies((prev) => ({ ...prev, analytics: checked })); + setConsentCookies({ ...consentCookies, analytics: checked }); reload(); }} /> @@ -115,7 +115,7 @@ function CookieModal() { { setConsentCookies((prev) => ({ ...prev, customization: checked })); reload(); diff --git a/app/lib/getTelefuncContext.ts b/app/lib/getTelefuncContext.ts new file mode 100644 index 0000000..5071844 --- /dev/null +++ b/app/lib/getTelefuncContext.ts @@ -0,0 +1,18 @@ +import type { FastifyRequest, FastifyReply } from "fastify"; + +import { getContext } from "telefunc"; + +export function getTelefuncContext() { + const context = getContext<{ + fastify: { + request: FastifyRequest; + reply: FastifyReply; + }; + }>(); + + return { + ...context, + reply: context.fastify.reply, + request: context.fastify.request, + }; +} diff --git a/app/services/CookieParser.ts b/app/services/CookieParser.ts index 12f95eb..12bed49 100644 --- a/app/services/CookieParser.ts +++ b/app/services/CookieParser.ts @@ -1,3 +1,5 @@ +import { FastifyReply } from "fastify"; + export class CookieParser { private rawCookies: string; private cookies: Record; @@ -25,4 +27,18 @@ export class CookieParser { if (formatter) return formatter(value); return value; } + + set(reply: FastifyReply, key: string, value: string, daysDuration = 30): FastifyReply { + const options = { + path: "/", + httpOnly: true, + secure: process.env.NODE_ENV === "production", + expires: new Date(Date.now() + 60 * 60 * 24 * daysDuration * 1000), + }; + + reply.setCookie(key, value, options); + this.cookies[key] = value; + + return reply; + } }