joye-backend-utility 4.1.22-test5 → 4.1.22-test7

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.
package/dist/jwt.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export declare const createToken: (payload: object, expiresIn: string) => Promise<any>;
2
- export declare const jwtVerify: (token: string) => Promise<unknown>;
2
+ export declare const jwtVerify: (token: string) => Promise<void>;
package/dist/jwt.js CHANGED
@@ -5,11 +5,9 @@ const jwt = require('jsonwebtoken');
5
5
  const fs = require('fs');
6
6
  // const JWT_SECRET = '3s6v9y$B&E)H+MbQeThWmZq4t7w!z%C*F-JaNcRfUjXn2r5u8x/A?D(G+KbPeSgV';
7
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 = '';
12
8
  const createToken = async (payload, expiresIn) => {
9
+ const JWT_PRIVATE_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key`, 'utf8');
10
+ // const JWT_PUBLIC_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key.pub`, 'utf8');
13
11
  const token = jwt.sign(payload, { key: JWT_PRIVATE_KEY.replace(/\\n/gm, '\n'), passphrase: '64d5f73bb3f132821122d68330263edd44023810a1f05efb701fc7ec8d0f6382' }, {
14
12
  expiresIn,
15
13
  algorithm: 'RS256',
@@ -17,12 +15,15 @@ const createToken = async (payload, expiresIn) => {
17
15
  return token;
18
16
  };
19
17
  exports.createToken = createToken;
20
- const jwtVerify = async (token) => new Promise(resolve => {
21
- jwt.verify(token, JWT_PUBLIC_KEY.replace(/\\n/gm, '\n'), async (err, decoded) => {
22
- if (err) {
23
- return resolve(err);
24
- }
25
- return resolve(decoded);
18
+ const jwtVerify = async (token) => {
19
+ const JWT_PUBLIC_KEY = fs.readFileSync(`jwt-keys/jwtRS256.key.pub`, 'utf8');
20
+ new Promise(resolve => {
21
+ jwt.verify(token, JWT_PUBLIC_KEY.replace(/\\n/gm, '\n'), async (err, decoded) => {
22
+ if (err) {
23
+ return resolve(err);
24
+ }
25
+ return resolve(decoded);
26
+ });
26
27
  });
27
- });
28
+ };
28
29
  exports.jwtVerify = jwtVerify;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "joye-backend-utility",
3
- "version": "4.1.22-test5",
3
+ "version": "4.1.22-test7",
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",