Created
September 23, 2024 11:48
-
-
Save chientrm/a0f2ff2078e78b14b47e0c240a2a9ba8 to your computer and use it in GitHub Desktop.
Encrypt Payload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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