{"id":16534545,"url":"https://github.com/iamolegga/nestjs-cookie-session","last_synced_at":"2025-08-21T13:33:02.129Z","repository":{"id":35162798,"uuid":"215299986","full_name":"iamolegga/nestjs-cookie-session","owner":"iamolegga","description":"Idiomatic Cookie Session Module for NestJS. Built on top of `cookie-session` 😻","archived":false,"fork":false,"pushed_at":"2024-05-29T02:29:11.000Z","size":4786,"stargazers_count":51,"open_issues_count":7,"forks_count":3,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-29T16:03:35.050Z","etag":null,"topics":["cookie","cookie-session","express","expressjs","nest","nestjs","session"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/iamolegga.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2019-10-15T13:00:53.000Z","updated_at":"2024-06-03T04:14:41.675Z","dependencies_parsed_at":"2024-04-08T03:26:25.404Z","dependency_job_id":"1f38d0ce-1672-453e-abb3-3ae339acb430","html_url":"https://github.com/iamolegga/nestjs-cookie-session","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fnestjs-cookie-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fnestjs-cookie-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fnestjs-cookie-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iamolegga%2Fnestjs-cookie-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iamolegga","download_url":"https://codeload.github.com/iamolegga/nestjs-cookie-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230516192,"owners_count":18238353,"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","cookie-session","express","expressjs","nest","nestjs","session"],"created_at":"2024-10-11T18:24:31.266Z","updated_at":"2024-12-20T00:08:47.883Z","avatar_url":"https://github.com/iamolegga.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003enestjs-cookie-session\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/nestjs-cookie-session\"\u003e\n    \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/v/nestjs-cookie-session\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/nestjs-cookie-session\"\u003e\n    \u003cimg alt=\"npm\" src=\"https://img.shields.io/npm/dm/nestjs-cookie-session\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/iamolegga/nestjs-cookie-session/actions\"\u003e\n    \u003cimg alt=\"GitHub branch checks state\" src=\"https://badgen.net/github/checks/iamolegga/nestjs-cookie-session\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://codeclimate.com/github/iamolegga/nestjs-cookie-session/test_coverage\"\u003e\n    \u003cimg src=\"https://api.codeclimate.com/v1/badges/7edd108bf29b26be86b7/test_coverage\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://snyk.io/test/github/iamolegga/nestjs-cookie-session\"\u003e\n    \u003cimg alt=\"Known Vulnerabilities\" src=\"https://snyk.io/test/github/iamolegga/nestjs-cookie-session/badge.svg\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://libraries.io/npm/nestjs-cookie-session\"\u003e\n    \u003cimg alt=\"Libraries.io\" src=\"https://img.shields.io/librariesio/release/npm/nestjs-cookie-session\" /\u003e\n  \u003c/a\u003e\n  \u003cimg alt=\"Dependabot\" src=\"https://badgen.net/github/dependabot/iamolegga/nestjs-cookie-session\" /\u003e\n  \u003cimg alt=\"Supported platforms: Express\" src=\"https://img.shields.io/badge/platforms-Express-green\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003eIdiomatic Cookie Session Module for NestJS. Built on top of \u003ca href=\"https://npm.im/cookie-session\"\u003ecookie-session\u003c/a\u003e 😎\u003c/p\u003e\n\nThis module implements a session with storing data directly in `Cookie`.\n\nIf you want to store data in one of [external stores](https://github.com/expressjs/session#compatible-session-stores) and passing ID of session to client via `Cookie`/`Set-Cookie` headers, you can look at [nestjs-session](https://github.com/iamolegga/nestjs-session).\n\n## Example\n\nRegister module:\n\n```ts\n// app.module.ts\nimport { Module } from '@nestjs/common';\nimport {\n  NestCookieSessionOptions,\n  CookieSessionModule,\n} from 'nestjs-cookie-session';\nimport { ViewsController } from './views.controller';\n\n@Module({\n  imports: [\n    // sync params:\n\n    CookieSessionModule.forRoot({\n      session: { secret: 'keyboard cat' },\n    }),\n\n    // or async:\n\n    CookieSessionModule.forRootAsync({\n      imports: [ConfigModule],\n      inject: [Config],\n      //              TIP: to get autocomplete in return object\n      //                  add `NestCookieSessionOptions` here ↓↓↓\n      useFactory: async (config: Config): Promise\u003cNestCookieSessionOptions\u003e =\u003e {\n        return {\n          session: { secret: config.secret },\n        };\n      },\n    }),\n  ],\n  controllers: [ViewsController],\n})\nexport class AppModule {}\n```\n\nUse in controllers with NestJS built-in `Session` decorator:\n\n```ts\n// views.controller.ts\nimport { Controller, Get, Session } from '@nestjs/common';\n\n@Controller('views')\nexport class ViewsController {\n  @Get()\n  getViews(@Session() session: { views?: number }) {\n    session.views = (session.views || 0) + 1;\n    return session.views;\n  }\n}\n```\n\nTo run examples:\n\n```sh\ngit clone https://github.com/iamolegga/nestjs-cookie-session.git\ncd nestjs-cookie-session\nnpm i\nnpm run build\ncd example\nnpm i\nnpm start\n```\n\n## Install\n\n```sh\nnpm i nestjs-cookie-session cookie-session @types/cookie-session\n```\n\n## API\n\n### CookieSessionModule\n\n`CookieSessionModule` class has two static methods, that returns `DynamicModule`, that you need to import:\n\n- `CookieSessionModule.forRoot` for sync configuration without dependencies\n- `CookieSessionModule.forRootAsync` for sync/async configuration with dependencies\n\n### CookieSessionModule.forRoot\n\nAccept `NestCookieSessionOptions`. Returns NestJS `DynamicModule` for import.\n\n### CookieSessionModule.forRootAsync\n\nAccept `NestCookieSessionAsyncOptions`. Returns NestJS `DynamicModule` for import.\n\n### NestCookieSessionOptions\n\n`NestCookieSessionOptions` is the interface of all options, has next properties:\n\n- `session` - **required** - [cookie-session options](https://github.com/expressjs/cookie-session#options).\n- `forRoutes` - **optional** - same as NestJS built-in `MiddlewareConfigProxy['forRoutes']` [See examples in official docs](https://docs.nestjs.com/middleware#applying-middleware). Specify routes, that should have access to session. If `forRoutes` and `exclude` will not be set, then sessions will be set to all routes.\n- `exclude` - **optional** - same as NestJS built-in `MiddlewareConfigProxy['exclude']` [See examples in official docs](https://docs.nestjs.com/middleware#applying-middleware). Specify routes, that should not have access to session. If `forRoutes` and `exclude` will not be set, then sessions will be set to all routes.\n\n### NestCookieSessionAsyncOptions\n\n`NestCookieSessionOptions` is the interface of options to create cookie session module, that depends on other modules, has next properties:\n\n- `imports` - **optional** - modules, that cookie session module depends on. See [official docs](https://docs.nestjs.com/modules).\n- `inject` - **optional** - providers from `imports`-property modules, that will be passed as arguments to `useFactory` method.\n- `useFactory` - **required** - method, that returns `NestCookieSessionOptions`.\n\n## Migration\n\n### v2\n\n`cookie-session` and `@types/cookie-session` are moved to peer dependencies, so you can update them independently.\n\n\u003ch2 align=\"center\"\u003eDo you use this library?\u003cbr/\u003eDon't be shy to give it a star! ★\u003c/h2\u003e\n\n\u003ch3 align=\"center\"\u003eAlso if you are into NestJS you might be interested in one of my \u003ca href=\"https://github.com/iamolegga#nestjs\"\u003eother NestJS libs\u003c/a\u003e.\u003c/h3\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamolegga%2Fnestjs-cookie-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiamolegga%2Fnestjs-cookie-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiamolegga%2Fnestjs-cookie-session/lists"}