add options.header
This commit is contained in:
@@ -100,7 +100,7 @@ Argument | Type | Status | Defa
|
|||||||
`secret` | `string`, `JsonWebKey`, `CryptoKey` | required | - | A string which is used to sign the payload.
|
`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` | `string`, `object` | optional | `HS256` | Either the `algorithm` string or an object.
|
||||||
`options.algorithm` | `string` | optional | `HS256` | See [Available Algorithms](#available-algorithms)
|
`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`
|
#### `return`
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export async function sign<Payload = {}, Header = {}>(payload: JwtPayload<Payloa
|
|||||||
if (typeof options === "string")
|
if (typeof options === "string")
|
||||||
options = { algorithm: options }
|
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")
|
if (!payload || typeof payload !== "object")
|
||||||
throw new Error("payload must be an object")
|
throw new Error("payload must be an object")
|
||||||
|
|||||||
Reference in New Issue
Block a user