Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | 2x 2x 2x | import { Service } from '../di/di'; import jwt from 'jsonwebtoken'; /** * @class JWTService * @description A service for generating JWT tokens. */ @Service() export class JWTService { private readonly secret: string; /** * @constructor * @description Initializes the secret from environment variables or a default value. */ constructor() { this.secret = process.env.JWT_SECRET || 'default-secret'; } /** * @method generateToken * @description Generates a JWT token. * @param {object} payload - The payload to include in the token. * @returns {string} The generated token. */ public generateToken(payload: object): string { return jwt.sign(payload, this.secret, { expiresIn: '1h' }); } } |