Skip to content

Commit

Permalink
feat: create a cookie decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Jul 24, 2023
1 parent 4ff8eea commit f83c283
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { ExecutionContext, createParamDecorator } from '@nestjs/common';
import { NestCookieRequest } from './cookie.interface';

export const Cookies = createParamDecorator(
(data: string | undefined, context: ExecutionContext) => {
const req = context.switchToHttp().getRequest<NestCookieRequest<{}>>();
if (data) {
return req.cookies[data];
}
return req.cookies;
},
);
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './decorator';
export * from './cookie.module';
export * from './cookie.interface';
export * from './cookies.interceptor';

0 comments on commit f83c283

Please sign in to comment.