Skip to content

Commit

Permalink
create: custom decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
adiCacti committed May 13, 2022
1 parent c07c225 commit e6e2f7e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/auth/decorator/get-user.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createParamDecorator, ExecutionContext } from '@nestjs/common';

export const GetUser = createParamDecorator(
(data: string | undefined, ctx: ExecutionContext) => {
const request = ctx.switchToHttp().getRequest();
if (data) {
return request.user[data];
}
return request.user;
},
);
1 change: 1 addition & 0 deletions src/auth/decorator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './get-user.decorator';

0 comments on commit e6e2f7e

Please sign in to comment.