{"id":41277871,"url":"https://github.com/maybemaby/fastify-iron-session","last_synced_at":"2026-01-23T02:44:10.468Z","repository":{"id":214829283,"uuid":"737475210","full_name":"maybemaby/fastify-iron-session","owner":"maybemaby","description":"Fastify plugin to use iron-session.","archived":false,"fork":false,"pushed_at":"2024-07-06T05:53:35.000Z","size":119,"stargazers_count":0,"open_issues_count":4,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-09T06:08:02.641Z","etag":null,"topics":["encryption","fastify","fastify-plugin","session"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maybemaby.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2023-12-31T07:02:57.000Z","updated_at":"2024-07-06T05:53:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"4b98963b-6c02-40ad-aa0c-36f8c2f59d14","html_url":"https://github.com/maybemaby/fastify-iron-session","commit_stats":null,"previous_names":["maybemaby/fastify-iron-session"],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/maybemaby/fastify-iron-session","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybemaby%2Ffastify-iron-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybemaby%2Ffastify-iron-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybemaby%2Ffastify-iron-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybemaby%2Ffastify-iron-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maybemaby","download_url":"https://codeload.github.com/maybemaby/fastify-iron-session/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maybemaby%2Ffastify-iron-session/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28679138,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T01:00:35.747Z","status":"online","status_checked_at":"2026-01-23T02:00:08.296Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["encryption","fastify","fastify-plugin","session"],"created_at":"2026-01-23T02:44:09.987Z","updated_at":"2026-01-23T02:44:10.459Z","avatar_url":"https://github.com/maybemaby.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fastify-iron-session\n![GitHub License](https://img.shields.io/github/license/maybemaby/fastify-iron-session) [![npm](https://img.shields.io/npm/v/fastify-iron-session)](https://www.npmjs.com/package/fastify-iron-session)\n\n\nFastify plugin for using encrypted sessions through [iron-session](https://github.com/vvo/iron-session?tab=readme-ov-file).\n\n## Install\n\n```\nnpm i fastify-iron-session\n```\n\n## Usage\n\nRegistration\n```typescript\nimport ironSession from \"fastify-iron-session\";\n\nfastify.register(ironSession, {\n  // (Optional) Name of session, will decorate the request with this name. Defaults to 'session'\n  sessionName: \"customSessionName\",\n  cookieName: \"cookieName\",\n  // String or array of objects used for signing the session cookie, must be at least 32 characters long. See iron-session docs for more information.\n  password: \"at-least-32-characters-long-password\",\n  // See iron-session docs for more information\n  ttl: 3600, // Seconds, defaults to 2 weeks,\n  // (Optional) Per iron-session docs: Any option available from jshttp/cookie#serialize except for encode which is not a Set-Cookie Attribute. See Mozilla Set-Cookie Attributes and Chrome Cookie Fields. Default to:\n  cookieOptions: {\n  httpOnly: true,\n  secure: true, // set this to false in local (non-HTTPS) development\n  sameSite: \"lax\",// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite#lax\n  maxAge: (ttl === 0 ? 2147483647 : ttl) - 60, // Expire cookie before the session expires.\n  path: \"/\",\n  }\n});\n```\n\nMultiple sessions\n\n```typescript\n// Register multiple sessions using an array of options\nfastify.register(ironSession, [\n  {\n  sessionName: \"session1\",\n  cookieName: \"cookieName1\"\n  // ...\n  },\n  {\n    sessionName: \"session2\",\n    cookieName: \"cookieName2\"\n    // ...\n  }\n]);\n```\n\nSetting session data \n```typescript\nfastify.post(\"/login\", async (req, reply) =\u003e {\n  // ...Some login logic\n  const session = await req.session();\n  session.id = \"abc123\";\n  session.name = \"John Doe\";\n\n  await session.save();\n\n  // Return a response\n});\n```\n\nDeleting session data\n```typescript\nfastify.post(\"/logout\", async (req, reply) =\u003e {\n  // ...Some logout logic\n  (await req.session()).destroy();\n\n  // Return a response\n});\n```\n\n## Session Type Overrides\nTo override the default session type:\n\n```typescript\ndeclare module \"fastify-iron-session\" {\n  interface SessionData {\n    user: {\n      id: string;\n      name: string;\n    };\n  }\n}\n```\n\nIf you have a custom session name, you can do:\n\n```typescript\nimport type { IronSession } from \"fastify-iron-session\";\n\ndeclare module \"fastify-iron-session\" {\n  interface SessionData {\n    user: {\n      id: string;\n      name: string;\n    };\n  }\n}\n\ndeclare module \"fastify\" {\n  interface FastifyRequest {\n    customSessionName: () =\u003e Promise\u003cIronSession\u003cSessionData\u003e\u003e;\n  }\n}\n```\n\n## Usage with Next.js\n\nIf you're using Nextjs with iron-session already, you can share the same session between Fastify and Nextjs by using the same cookie name and password. You will need to make sure your setup allows sharing cookies. My recommendation if you're not hosting on the same domain is using Next's rewrite config option. You can see an example for this in the [examples folder](examples/with-next/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaybemaby%2Ffastify-iron-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaybemaby%2Ffastify-iron-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaybemaby%2Ffastify-iron-session/lists"}