Options fix
This commit is contained in:
2
index.js
2
index.js
@@ -56,6 +56,7 @@ class JWT {
|
|||||||
async sign(payload, secret, options = { algorithm: 'HS256', header: { typ: 'JWT' } }) {
|
async sign(payload, secret, options = { algorithm: 'HS256', header: { typ: 'JWT' } }) {
|
||||||
if (typeof options === 'string')
|
if (typeof options === 'string')
|
||||||
options = { algorithm: options, header: { typ: 'JWT' } }
|
options = { algorithm: options, header: { typ: 'JWT' } }
|
||||||
|
options = { algorithm: 'HS256', header: { typ: 'JWT' }, ...options }
|
||||||
if (payload === null || typeof payload !== 'object')
|
if (payload === null || typeof payload !== 'object')
|
||||||
throw new Error('payload must be an object')
|
throw new Error('payload must be an object')
|
||||||
if (typeof secret !== 'string')
|
if (typeof secret !== 'string')
|
||||||
@@ -82,6 +83,7 @@ class JWT {
|
|||||||
async verify(token, secret, options = { algorithm: 'HS256', throwError: false }) {
|
async verify(token, secret, options = { algorithm: 'HS256', throwError: false }) {
|
||||||
if (typeof options === 'string')
|
if (typeof options === 'string')
|
||||||
options = { algorithm: options }
|
options = { algorithm: options }
|
||||||
|
options = { algorithm: 'HS256', throwError: false, ...options }
|
||||||
if (typeof token !== 'string')
|
if (typeof token !== 'string')
|
||||||
throw new Error('token must be a string')
|
throw new Error('token must be a string')
|
||||||
if (typeof secret !== 'string')
|
if (typeof secret !== 'string')
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"lockfileVersion": 2,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"jest": "^28.1.0"
|
"jest": "^28.1.0"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@tsndr/cloudflare-worker-jwt",
|
"name": "@tsndr/cloudflare-worker-jwt",
|
||||||
"version": "1.4.3",
|
"version": "1.4.4",
|
||||||
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
"description": "A lightweight JWT implementation with ZERO dependencies for Cloudflare Worker",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user