{ "$schema": "https://ui.shadcn.com/schema/registry-item.json", "name": "cookies-server", "files": [ { "path": "registry/lib/cookies.server.ts", "content": "\"use server\"\n\nimport { ResponseCookie } from \"next/dist/compiled/@edge-runtime/cookies\"\nimport { cookies } from \"next/headers\"\n\ntype SameSiteOption = \"lax\" | \"strict\" | \"none\"\n\ninterface CookieOptions {\n path?: string\n secure?: boolean\n sameSite?: SameSiteOption\n domain?: string\n expires?: Date\n maxAge?: number\n httpOnly?: boolean\n}\nconst COOKIES_DEFAULT_OPTIONS: Required> = {\n path: \"/\",\n secure: true,\n sameSite: \"lax\",\n httpOnly: true,\n expires: new Date(Date.now() + 60 * 60 * 24 * 7),\n maxAge: 60 * 60 * 24 * 7,\n}\n\n/**\n * This module provides a way to interact with cookies on the server.\n * The first ServerCookies object is for Next.js 12 and later. while the second set is for Next.js 15.\n * you will get error if you use the first set in Next.js 15 because async/await is expected.\n *\n * - `set` sets a cookie with the given name and value.\n * - `get` gets the value of a cookie with the given name.\n * - `delete` deletes a cookie with the given name.\n */\n\n/**\n * This is for Next.js 13 - 14.\n\nexport const ServerCookies = {\n set(name: string, value: string, options: Partial = {}) {\n const cookieOptions: ResponseCookie = {\n name,\n value,\n path: options.path || COOKIES_DEFAULT_OPTIONS.path,\n secure: options.secure ?? COOKIES_DEFAULT_OPTIONS.secure,\n sameSite: options.sameSite || COOKIES_DEFAULT_OPTIONS.sameSite,\n httpOnly: options.httpOnly ?? COOKIES_DEFAULT_OPTIONS.httpOnly,\n expires: options.expires || COOKIES_DEFAULT_OPTIONS.expires,\n maxAge: options.maxAge || COOKIES_DEFAULT_OPTIONS.maxAge,\n };\n\n\n if (options.domain) {\n cookieOptions.domain = options.domain\n }\n\n cookies().set(cookieOptions)\n },\n\n get(name: string) {\n return cookies().get(name)?.value ?? null\n },\n\n delete(name: string) {\n cookies().delete(name)\n },\n}\n */\n\nexport const ServerCookiesNext15 = {\n async set(name: string, value: string, options: Partial = {}) {\n const cookieOptions: ResponseCookie = {\n name,\n value,\n path: options.path || COOKIES_DEFAULT_OPTIONS.path,\n secure: options.secure ?? COOKIES_DEFAULT_OPTIONS.secure,\n sameSite: options.sameSite || COOKIES_DEFAULT_OPTIONS.sameSite,\n httpOnly: options.httpOnly ?? COOKIES_DEFAULT_OPTIONS.httpOnly,\n expires: options.expires || COOKIES_DEFAULT_OPTIONS.expires,\n maxAge: options.maxAge || COOKIES_DEFAULT_OPTIONS.maxAge,\n }\n\n if (options.domain) {\n cookieOptions.domain = options.domain\n }\n\n ;(await cookies()).set(cookieOptions)\n },\n\n async get(name: string) {\n return (await cookies()).get(name)?.value ?? null\n },\n\n async delete(name: string) {\n ;(await cookies()).delete(name)\n },\n}\n", "type": "registry:lib", "target": "lib/cookies.server.ts" } ], "type": "registry:lib" }