UNPKG

bb-inspired

Version:

Core library for BB-inspired NestJS backend

34 lines 1.73 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var JwtValidationPipe_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.JwtValidationPipe = void 0; const common_1 = require("@nestjs/common"); const logger_1 = require("../../../utils/logger"); let JwtValidationPipe = JwtValidationPipe_1 = class JwtValidationPipe { constructor() { this.logger = new logger_1.AppLogger(JwtValidationPipe_1.name); } transform(value) { if (!value || typeof value !== 'string') { this.logger.warn('Invalid token format: not a string'); throw new common_1.BadRequestException('Invalid token format'); } const jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+$/; if (!jwtRegex.test(value)) { this.logger.warn('Invalid JWT token format'); throw new common_1.BadRequestException('Invalid JWT token format'); } return value; } }; exports.JwtValidationPipe = JwtValidationPipe; exports.JwtValidationPipe = JwtValidationPipe = JwtValidationPipe_1 = __decorate([ (0, common_1.Injectable)() ], JwtValidationPipe); //# sourceMappingURL=jwt-validation.pipe.js.map