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