{"id":13469575,"url":"https://github.com/maticzav/nookies","last_synced_at":"2025-05-12T13:18:49.169Z","repository":{"id":39381149,"uuid":"117610654","full_name":"maticzav/nookies","owner":"maticzav","description":"🍪 A set of cookie helpers for Next.js","archived":false,"fork":false,"pushed_at":"2025-02-13T10:38:46.000Z","size":52894,"stargazers_count":2333,"open_issues_count":32,"forks_count":78,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-05-12T13:18:19.011Z","etag":null,"topics":["cookie","hacktoberfest","nextjs","react","zeit"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maticzav.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"maticzav","patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2018-01-16T00:32:30.000Z","updated_at":"2025-05-10T12:05:17.000Z","dependencies_parsed_at":"2023-01-21T23:00:58.081Z","dependency_job_id":"3a912697-7e4c-46b3-884a-4f06c9000a09","html_url":"https://github.com/maticzav/nookies","commit_stats":{"total_commits":495,"total_committers":27,"mean_commits":"18.333333333333332","dds":"0.16767676767676765","last_synced_commit":"8e090c462d15123654cf58853248755d6e112763"},"previous_names":[],"tags_count":31,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fnookies","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fnookies/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fnookies/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maticzav%2Fnookies/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maticzav","download_url":"https://codeload.github.com/maticzav/nookies/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745196,"owners_count":21957319,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cookie","hacktoberfest","nextjs","react","zeit"],"created_at":"2024-07-31T15:01:45.624Z","updated_at":"2025-05-12T13:18:49.114Z","avatar_url":"https://github.com/maticzav.png","language":"TypeScript","funding_links":["https://github.com/sponsors/maticzav"],"categories":["TypeScript","miscellaneous","🌐 Web Development - Frontend"],"sub_categories":[],"readme":"# nookies :cookie:\n\n![Working](https://github.com/maticzav/nookies/workflows/Release/badge.svg)\n[![npm version](https://badge.fury.io/js/nookies.svg)](https://badge.fury.io/js/nookies)\n\n\u003e A collection of cookie helpers for Next.js\n\n## Features\n\n- ✨ SSR support, for setter, parser and destroy\n- ⚙️ Custom Express server support\n- 🪶 super light\n- 🛡 perfect for authentication\n\nSetting and destroying cookies also works on server-side.\n\n## Quick start\n\n`yarn add nookies`\n\n\u003e You can play with the example code [here](https://codesandbox.io/s/charming-herschel-7z362).\n\n### ServerSide cookies\n\n```js\nimport nookies from 'nookies'\n\nexport default function Me() {\n  return \u003cdiv\u003eMy profile\u003c/div\u003e\n}\n\nexport async function getServerSideProps(ctx) {\n  // Parse\n  const cookies = nookies.get(ctx)\n\n  // Set\n  nookies.set(ctx, 'fromGetInitialProps', 'value', {\n    maxAge: 30 * 24 * 60 * 60,\n    path: '/',\n  })\n\n  // Destroy\n  // nookies.destroy(ctx, 'cookieName')\n\n  return { cookies }\n}\n```\n\n## Client-only Cookies\n\n```js\nimport { parseCookies, setCookie, destroyCookie } from 'nookies'\n\nfunction handleClick() {\n  // Simply omit context parameter.\n  // Parse\n  const cookies = parseCookies()\n  console.log({ cookies })\n\n  // Set\n  setCookie(null, 'fromClient', 'value', {\n    maxAge: 30 * 24 * 60 * 60,\n    path: '/',\n  })\n\n  // Destroy\n  // destroyCookie(null, 'cookieName')\n}\n\nexport default function Me() {\n  return \u003cbutton onClick={handleClick}\u003eSet Cookie\u003c/button\u003e\n}\n```\n\n## Custom Express server cookies\n\n```js\nconst express = require('express');\nconst dev = process.env.NODE_ENV !== 'production';\nconst app = next({ dev });\nconst handle = app.getRequestHandler();\nconst { parseCookies, setCookie, destroyCookie } = require('nookies');\n\napp.prepare()\n    .then(() =\u003e {\n        const server = express();\n\n        server.get('/page', (req, res) =\u003e {\n\n          // Notice how the request object is passed\n          const parsedCookies = parseCookies({ req });\n\n          // Notice how the response object is passed\n          setCookie({ res }, 'fromServer', 'value', {\n            maxAge: 30 * 24 * 60 * 60,\n            path: '/page',\n          });\n\n          // destroyCookie({ res }, 'fromServer');\n\n          return handle(req, res);\n        });\n\n    );\n```\n\n## Reference\n\n\u003e For client side usage, omit the `ctx` parameter. You can do so by setting it to an empty object (`{}`), `null` or `undefined`.\n\n### `parseCookies(ctx, options)` or `nookies.get(ctx, options)`\n\n- **ctx:** `Next.js context` || `(Express request object)`\n- **options:**\n  - **decode:** `a custom resolver function (default: decodeURIComponent)`\n\n### `setCookie(ctx, name, value, options)` or `nookies.set(ctx, name, value, options)`\n\n\u003e Don't forget to end your response on the server with `res.send()`.\n\n- **ctx:** `(Next.js context)` || `(Express request object)`\n- **name:** cookie name\n- **value:** cookie value\n- **options:**\n  - **domain**\n  - **encode**\n  - **expires**\n  - **httpOnly**\n  - **maxAge**\n  - **path**\n  - **sameSite**\n  - **secure**\n\n### `destroyCookie(ctx, name, options)` or `nookies.destroy(ctx, 'token', options)`\n\n\u003e Don't forget to end your response on the server with `res.send()`. This might be the reason your cookie isn't removed.\n\n- **ctx:** `(Next.js context)` || `(Express response object)`\n- **name:** cookie name\n- **options:**\n  - **domain**\n  - **path**\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fnookies","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaticzav%2Fnookies","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaticzav%2Fnookies/lists"}