Skip to content

Instantly share code, notes, and snippets.

@chientrm
Created September 23, 2024 11:48
Show Gist options
  • Save chientrm/a0f2ff2078e78b14b47e0c240a2a9ba8 to your computer and use it in GitHub Desktop.
Save chientrm/a0f2ff2078e78b14b47e0c240a2a9ba8 to your computer and use it in GitHub Desktop.
Encrypt Payload
import { PKCS8 } from '$env/static/private';
import { COOKIE_HOST, audience, issuer } from '$lib/constants';
import { SignJWT, importPKCS8, type JWTPayload } from 'jose';
const forPrivateKey = importPKCS8(PKCS8, 'RS512');
export const sign = async <T extends JWTPayload>(data: T) =>
new SignJWT(data)
.setProtectedHeader({ alg: 'RS512' })
.setIssuedAt()
.setIssuer(issuer)
.setAudience(audience)
.setExpirationTime('30d')
.sign(await forPrivateKey);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment