diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-08-04 20:49:12 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-08-04 20:49:12 +0900 |
| commit | ff959dadb1f990173b9df3105ccfc96b1c6c092e (patch) | |
| tree | 4690c2aabafaedb50f86ece4900c9616d9518947 /frontend/app/.server/cookie.ts | |
| parent | fa7755592845a44928e88d2ab78cc04425aa9024 (diff) | |
| parent | f4bae7f755ca25b2547dc98b2db2fdb255948bc5 (diff) | |
| download | iosdc-japan-2024-albatross-ff959dadb1f990173b9df3105ccfc96b1c6c092e.tar.gz iosdc-japan-2024-albatross-ff959dadb1f990173b9df3105ccfc96b1c6c092e.tar.zst iosdc-japan-2024-albatross-ff959dadb1f990173b9df3105ccfc96b1c6c092e.zip | |
Merge branch 'feat/admin-pages'
Diffstat (limited to 'frontend/app/.server/cookie.ts')
| -rw-r--r-- | frontend/app/.server/cookie.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/frontend/app/.server/cookie.ts b/frontend/app/.server/cookie.ts new file mode 100644 index 0000000..cccbe78 --- /dev/null +++ b/frontend/app/.server/cookie.ts @@ -0,0 +1,41 @@ +import { Cookie, CookieOptions } from "@remix-run/server-runtime"; +import { parse, serialize } from "cookie"; + +// Remix's createCookie() returns "structured" cookies, which are cookies that hold a JSON-encoded object. +// This is not suitable for interoperation with other systems that expect a simple string value. +// This function creates an "unstructured" cookie, a simple plain text. +export function createUnstructuredCookie( + name: string, + cookieOptions?: CookieOptions, +): Cookie { + const { secrets = [], ...options } = { + path: "/", + sameSite: "lax" as const, + ...cookieOptions, + }; + + return { + get name() { + return name; + }, + get isSigned() { + return secrets.length > 0; + }, + get expires() { + return typeof options.maxAge !== "undefined" + ? new Date(Date.now() + options.maxAge * 1000) + : options.expires; + }, + async parse(cookieHeader, parseOptions) { + if (!cookieHeader) return null; + const cookies = parse(cookieHeader, { ...options, ...parseOptions }); + return name in cookies ? cookies[name] : null; + }, + async serialize(value, serializeOptions) { + return serialize(name, value, { + ...options, + ...serializeOptions, + }); + }, + }; +} |
