From 29aa3b01985aca8ab9a67629b37c07d7930be501 Mon Sep 17 00:00:00 2001 From: Tobias Schneider Date: Wed, 22 Jun 2022 19:11:53 +0200 Subject: [PATCH] Options fix --- index.js | 2 ++ package-lock.json | 4 ++-- package.json | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 4266fad..4f20b42 100644 --- a/index.js +++ b/index.js @@ -56,6 +56,7 @@ class JWT { async sign(payload, secret, options = { algorithm: 'HS256', header: { typ: 'JWT' } }) { if (typeof options === 'string') options = { algorithm: options, header: { typ: 'JWT' } } + options = { algorithm: 'HS256', header: { typ: 'JWT' }, ...options } if (payload === null || typeof payload !== 'object') throw new Error('payload must be an object') if (typeof secret !== 'string') @@ -82,6 +83,7 @@ class JWT { async verify(token, secret, options = { algorithm: 'HS256', throwError: false }) { if (typeof options === 'string') options = { algorithm: options } + options = { algorithm: 'HS256', throwError: false, ...options } if (typeof token !== 'string') throw new Error('token must be a string') if (typeof secret !== 'string') diff --git a/package-lock.json b/package-lock.json index 4147878..effae6a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@tsndr/cloudflare-worker-jwt", - "version": "1.4.3", + "version": "1.4.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@tsndr/cloudflare-worker-jwt", - "version": "1.4.3", + "version": "1.4.4", "license": "MIT", "devDependencies": { "jest": "^28.1.0" diff --git a/package.json b/package.json index a028dd2..74e6b2d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@tsndr/cloudflare-worker-jwt", - "version": "1.4.3", + "version": "1.4.4", "description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker", "main": "index.js", "scripts": {