joye-backend-utility 4.1.22-test4 → 4.1.22-test6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/jwt.js +10 -4
  2. package/package.json +1 -1
package/dist/jwt.js CHANGED
@@ -2,17 +2,23 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jwtVerify = exports.createToken = void 0;
4
4
  const jwt = require('jsonwebtoken');
5
- const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
5
+ const fs = require('fs');
6
+ // const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
7
+ // const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
8
+ // const JWT_PRIVATE_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key`, 'utf8');
9
+ // const JWT_PUBLIC_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key.pub`, 'utf8');
10
+ const JWT_PRIVATE_KEY = '';
11
+ const JWT_PUBLIC_KEY = '';
6
12
  const createToken = async (payload, expiresIn) => {
7
- const token = jwt.sign(payload, process.env.JWT_SECRET || JWT_SECRET, {
13
+ const token = jwt.sign(payload, { key: JWT_PRIVATE_KEY.replace(/\\n/gm, '\n'), passphrase: '64d5f73bb3f132821122d68330263edd44023810a1f05efb701fc7ec8d0f6382' }, {
8
14
  expiresIn,
9
- algorithm: 'HS256',
15
+ algorithm: 'RS256',
10
16
  });
11
17
  return token;
12
18
  };
13
19
  exports.createToken = createToken;
14
20
  const jwtVerify = async (token) => new Promise(resolve => {
15
- jwt.verify(token, process.env.JWT_SECRET || JWT_SECRET, async (err, decoded) => {
21
+ jwt.verify(token, JWT_PUBLIC_KEY.replace(/\\n/gm, '\n'), async (err, decoded) => {
16
22
  if (err) {
17
23
  return resolve(err);
18
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joye-backend-utility",
3
- "version": "4.1.22-test4",
3
+ "version": "4.1.22-test6",
4
4
  "description": "Joye backend utility for db functions and common functions",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",