Skip to content

Commit 5c019f6

Browse files
committed
chore: migrate createParamDecorator
1 parent fb2cb3f commit 5c019f6

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/user/user.decorator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { createParamDecorator } from '@nestjs/common';
1+
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
22
import { SECRET } from '../config';
33
import * as jwt from 'jsonwebtoken';
44

5-
export const User = createParamDecorator((data, req) => {
5+
export const User = createParamDecorator((data: any, ctx: ExecutionContext) => {
6+
const req = ctx.switchToHttp().getRequest();
67
// if route is protected, there is a user set in auth.middleware
78
if (!!req.user) {
89
return !!data ? req.user[data] : req.user;
@@ -14,5 +15,4 @@ export const User = createParamDecorator((data, req) => {
1415
const decoded: any = jwt.verify(token[1], SECRET);
1516
return !!data ? decoded[data] : decoded.user;
1617
}
17-
1818
});

0 commit comments

Comments
 (0)