1
0

Compare commits

...

2 Commits

Author SHA1 Message Date
9f74c8b56c 3.1.0 2024-10-03 19:25:44 +02:00
c7ce8686d3 add options.header 2024-10-03 19:25:22 +02:00
4 changed files with 5 additions and 5 deletions

View File

@@ -100,7 +100,7 @@ Argument | Type | Status | Defa
`secret` | `string`, `JsonWebKey`, `CryptoKey` | required | - | A string which is used to sign the payload.
`options` | `string`, `object` | optional | `HS256` | Either the `algorithm` string or an object.
`options.algorithm` | `string` | optional | `HS256` | See [Available Algorithms](#available-algorithms)
`options.keyid` | `string` | optional | `undefined` | The `keyid` or `kid` to be set in the header of the resulting JWT.
`options.header` | `object` | optional | `undefined` | Extend the header of the resulting JWT.
#### `return`

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "@tsndr/cloudflare-worker-jwt",
"version": "3.0.0",
"version": "3.1.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@tsndr/cloudflare-worker-jwt",
"version": "3.0.0",
"version": "3.1.0",
"license": "MIT",
"devDependencies": {
"@cloudflare/workers-types": "^4.20240925.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@tsndr/cloudflare-worker-jwt",
"version": "3.0.0",
"version": "3.1.0",
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
"type": "module",
"exports": "./index.js",

View File

@@ -147,7 +147,7 @@ export async function sign<Payload = {}, Header = {}>(payload: JwtPayload<Payloa
if (typeof options === "string")
options = { algorithm: options }
options = { algorithm: "HS256", header: { typ: "JWT" } as JwtHeader<Header>, ...options }
options = { algorithm: "HS256", header: { typ: "JWT", ...(options.header ?? {}) } as JwtHeader<Header>, ...options }
if (!payload || typeof payload !== "object")
throw new Error("payload must be an object")