mirror of
https://github.com/koreanbots/core.git
synced 2025-12-15 14:10:22 +00:00
* deps: bump critical deps version * chore: specify sentry and dd debug mode * chore: enable SwcMinify * chore: casing * deps: bump mongoose version to 6.8.3 * Revert "deps: bump mongoose version to 6.8.3" This reverts commit d5b90b5c0909545d4d21553d50c5681bd93a57a4. * deps: change mongoose version to 5.13.15 * fix: typing * deps: update audited deps * deps: update next-pwa and dd-trace@2 * deps: update dd-trace@3 and sentry * fix: redirects * fix: style * feat: redirect using next config * deps: update mongoose to 6.9.0 * chore: change next version in package.json * chore: change next version to 12.3.2 * fix: model compile issue * chore: lint * chore: remove any * deps: update jest version to 29 * deps: resolve remaining vulnerabilities --------- Co-authored-by: skinmaker1345 <me@skinmaker.dev>
28 lines
773 B
TypeScript
28 lines
773 B
TypeScript
import * as jwt from 'jsonwebtoken'
|
|
|
|
const publicPem = process.env.PUBLIC_PEM?.replace(/\\n/g, '\n')
|
|
const privateKey = process.env.PRIVATE_KEY?.replace(/\\n/g, '\n')
|
|
|
|
export function sign(payload: string | Record<string, unknown>, options?: JWTSignOption): string | null {
|
|
try {
|
|
return jwt.sign(payload, privateKey, options ? { ...options, algorithm: 'RS256', allowInsecureKeySizes: true } : { algorithm: 'RS256', allowInsecureKeySizes: true })
|
|
} catch {
|
|
return null
|
|
}
|
|
}
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function verify(token?: string): any | null {
|
|
if(!token) return null
|
|
try {
|
|
return jwt.verify(token, publicPem)
|
|
} catch(e) {
|
|
console.log(e)
|
|
return null
|
|
}
|
|
}
|
|
|
|
interface JWTSignOption {
|
|
expiresIn: number | string
|
|
}
|