import { UnauthorizedException , BadRequestException } from '@nestjs/common' ; import * as jwt from 'jsonwebtoken' ; import { configService } from './config.service' ; export class JwtManipulationService { public decodeJwtToken ( token , property ) { let result ; try { if ( ! token ) throw new Error ( ) ; let decodedJwtData ; try { decodedJwtData = jwt . verify ( token . split ( ' ' ) [ 1 ] , configService . getEnv ( 'SECRET_FOR_ACCESS_TOKEN' ) ) ; } catch ( error ) { throw new BadRequestException ( 'Token signature is not valid' ) ; } if ( property === 'all' ) result = decodedJwtData ; else result = decodedJwtData [ property ] ; } catch { throw new UnauthorizedException ( ) ; } return result ; } } const jwtManipulationService = new JwtManipulationService ( ) ; export { jwtManipulationService } ;