import { Injectable } from '@nestjs/common' ; import { randomBytes } from 'crypto' ; import type { Request } from 'express' ; import { Cookie , NestCookieRequest } from 'nest-cookies' ; @ Injectable ( ) export class CookieService { setCookie ( req , cookieName , value ? , options ? ) { value = value ? value : randomBytes ( 16 ) . toString ( 'hex' ) ; req . _cookies ?. length ? req . _cookies . push ( { name : cookieName , value : value , options , } ) : ( req . _cookies = [ { name : cookieName , value : value , options , } , ] ) ; return value ; } }