import jsonwebtoken from 'jsonwebtoken'; import { Request } from 'express'; require('dotenv/config'); export class SecurityUtils { static encode(object: any, expirationTime: string = '1h'): string { return jsonwebtoken.sign(object, process.env.JWT_SECRET, { expiresIn: expirationTime, }); } static decode(token: string): any { return jsonwebtoken.verify(token, process.env.JWT_SECRET); } static getRequestIp(request: Request) : string { return (request.headers['x-forwarded-for'] || request.connection.remoteAddress).toString() .split(',')[0]; } }