import jwt from "jsonwebtoken" ; import dayjs from "dayjs" ; import { IJWTToken } from "../../../cshub-shared/src/models" ; import { IUser } from "../../../cshub-shared/src/entities/user" ; import { Settings } from "../settings" ; export const sign = ( obj ) : string => { const newObj = JSON . parse ( JSON . stringify ( obj ) ) ; newObj . avatar = "" ; const jwtobj = { user : newObj , expirydate : dayjs ( ) . add ( Settings . TOKENAGEMILLISECONDS , "millisecond" ) . unix ( ) , } ; return jwt . sign ( jwtobj , Settings . JWTHASH ) ; } ; export const validateAccessToken = ( accessToken ) : IJWTToken | undefined => { try { return jwt . verify ( accessToken , Settings . JWTHASH ) as IJWTToken ; } catch ( e ) { } } ;