import { TokenGenerator , TokenValidator } from '@/domain/contracts/gateways' ; import { JwtPayload , sign , verify } from 'jsonwebtoken' ; export class JwtTokenHandler implements TokenGenerator , TokenValidator { constructor ( private readonly secret ) { } async generate ( { expirationInMs , key } ) { const expirationInSeconds = expirationInMs / 1000 ; return sign ( { key } , this . secret , { expiresIn : expirationInSeconds } ) ; } async validate ( { token } ) { const payload = verify ( token , this . secret ) as JwtPayload ; return payload . key ; } }