mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
26 lines
624 B
TypeScript
26 lines
624 B
TypeScript
import * as jwt from 'jsonwebtoken'
|
|
|
|
const publicPem = process.env.PUBLIC_PEM
|
|
const privateKey = process.env.PRIVATE_KEY
|
|
|
|
export function sign(payload: string | Record<string, unknown>, options?: JWTSignOption): string | null {
|
|
try {
|
|
return jwt.sign(payload, privateKey, options ? { ...options, algorithm: 'RS256' } : { algorithm: 'RS256' })
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function verify(token: string): any | null {
|
|
try {
|
|
return jwt.verify(token, publicPem)
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
interface JWTSignOption {
|
|
expiresIn: number | string
|
|
}
|