From d7840a4efa6c1bd0234b4b2d713090f0050ff77e Mon Sep 17 00:00:00 2001 From: Luk Lu Date: Wed, 9 Mar 2022 16:01:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20init(envi)=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E6=9D=A5=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index b820906..242b2e7 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,14 @@ const JsonWebToken = require('jsonwebtoken') const crypto = require('crypto') +const { workerData } = require('worker_threads') + +const my = {} module.exports = { + init (envi) { + my.tokenKey = envi.tokenKey + }, createToken: function (content, key) { // content 可以是数字,非空字符串或非空对象,不可以是数组。 // key 可以未定义,则默认设为空字符串,再转化为哈希。(jsonwebtoken 要求 key 必须有值) @@ -11,7 +17,7 @@ module.exports = { content, crypto .createHash('sha256') - .update(key || '', 'utf8') + .update(key || my.tokenKey || wo.envi.tokenKey || '', 'utf8') .digest('hex') ) } catch (exp) { @@ -24,7 +30,7 @@ module.exports = { token, crypto .createHash('sha256') - .update(key || '', 'utf8') + .update(key || my.tokenKey || wo.envi.tokenKey || '', 'utf8') .digest('hex') ) } catch (exp) {