UNPKG

@takentrade/takentrade-libs

Version:
27 lines (26 loc) 833 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GetUser = void 0; const common_1 = require("@nestjs/common"); exports.GetUser = (0, common_1.createParamDecorator)((data, ctx) => { const request = ctx.switchToHttp().getRequest(); const user = request.user; if (!user) { throw new common_1.UnauthorizedException('Invalid credentials or account information'); } if (!data) { return user; } if (data === 'sub') { const value = user.id || user.sub; if (!value) { throw new common_1.UnauthorizedException('User ID not found'); } return value; } const value = user[data]; if (value === undefined) { throw new common_1.UnauthorizedException(`User ${data} not found`); } return value; });