Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/trs/nestjs-cookie
Read cookies using decorators in NestJS
https://github.com/trs/nestjs-cookie
hacktoberfest
Last synced: 23 days ago
JSON representation
Read cookies using decorators in NestJS
- Host: GitHub
- URL: https://github.com/trs/nestjs-cookie
- Owner: trs
- Created: 2023-01-02T20:59:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-10-28T21:36:41.000Z (about 1 year ago)
- Last Synced: 2024-12-12T00:44:24.733Z (27 days ago)
- Topics: hacktoberfest
- Language: TypeScript
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NestJS Cookie
> Read cookies using decorators in NestJS
## Install
```sh
npm install nestjs-cookie
# or
yarn add nestjs-cookie
```## Usage
Use the `@Cookie` decorator to grab a cookie from the `cookie` header.
```ts
import { Controller } from '@nestjs/common';
import { Cookie } from 'nestjs-cookie';@Controller()
export class MyController {
@Get()
async myMethod(@Cookie('some_token') token: string) {
console.log(token);
}
}
```You can also grab a `Map` of all cookies using the `@Cookies` decorator
```ts
import { Controller } from '@nestjs/common';
import { Cookies } from 'nestjs-cookie';@Controller()
export class MyController {
@Get()
async myMethod(@Cookies() cookies: Map) {
console.log(cookies);
}
}
```