mirror of
https://github.com/standardnotes/server
synced 2026-09-13 00:45:26 -04:00
feat: add security package
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { sign } from 'jsonwebtoken'
|
||||
|
||||
import { TokenEncoderInterface } from './TokenEncoderInterface'
|
||||
|
||||
export class TokenEncoder<T> implements TokenEncoderInterface<T> {
|
||||
constructor(private jwtSecret: string) {}
|
||||
|
||||
encodeExpirableToken(data: T, expiresIn: string | number | undefined): string {
|
||||
return sign(data as Record<string, unknown>, this.jwtSecret, { algorithm: 'HS256', expiresIn })
|
||||
}
|
||||
|
||||
encodeToken(data: T): string {
|
||||
return sign(data as Record<string, unknown>, this.jwtSecret, { algorithm: 'HS256' })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user