@jayfong/x-server 2.1.4 → 2.1.5
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/lib/_cjs/services/jwt.js +6 -2
- package/lib/services/jwt.d.ts +3 -0
- package/lib/services/jwt.js +6 -2
- package/package.json +1 -1
package/lib/_cjs/services/jwt.js
CHANGED
|
@@ -24,17 +24,21 @@ class JwtService {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
async verify(token) {
|
|
27
|
-
|
|
27
|
+
var _this$options$onVerif, _this$options;
|
|
28
|
+
|
|
29
|
+
const data = await new Promise((resolve, reject) => {
|
|
28
30
|
_jsonwebtoken.default.verify(token, this.options.secret, {
|
|
29
31
|
ignoreExpiration: false
|
|
30
32
|
}, (err, data) => {
|
|
31
|
-
if (err) {
|
|
33
|
+
if (err || !data || typeof data === 'string' || !data.iat || !data.exp) {
|
|
32
34
|
reject(new _http_error.HttpError.Unauthorized());
|
|
33
35
|
} else {
|
|
34
36
|
resolve(data);
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
});
|
|
40
|
+
await ((_this$options$onVerif = (_this$options = this.options).onVerify) == null ? void 0 : _this$options$onVerif.call(_this$options, data));
|
|
41
|
+
return data;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
async verifyFromHttpHeaders(headers) {
|
package/lib/services/jwt.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
import jwt from 'jsonwebtoken';
|
|
2
3
|
import { BaseService } from './base';
|
|
3
4
|
import { MsValue } from 'vtils/date';
|
|
4
5
|
import type { IncomingHttpHeaders } from 'http';
|
|
6
|
+
import type { RequiredBy } from 'vtils/types';
|
|
5
7
|
export interface JwtServiceOptions {
|
|
6
8
|
secret: string;
|
|
7
9
|
ttl: MsValue;
|
|
10
|
+
onVerify?: (payload: RequiredBy<jwt.JwtPayload, 'iat' | 'exp'>) => any;
|
|
8
11
|
}
|
|
9
12
|
export declare class JwtService implements BaseService {
|
|
10
13
|
private options;
|
package/lib/services/jwt.js
CHANGED
|
@@ -14,17 +14,21 @@ export class JwtService {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
async verify(token) {
|
|
17
|
-
|
|
17
|
+
var _this$options$onVerif, _this$options;
|
|
18
|
+
|
|
19
|
+
const data = await new Promise((resolve, reject) => {
|
|
18
20
|
jwt.verify(token, this.options.secret, {
|
|
19
21
|
ignoreExpiration: false
|
|
20
22
|
}, (err, data) => {
|
|
21
|
-
if (err) {
|
|
23
|
+
if (err || !data || typeof data === 'string' || !data.iat || !data.exp) {
|
|
22
24
|
reject(new HttpError.Unauthorized());
|
|
23
25
|
} else {
|
|
24
26
|
resolve(data);
|
|
25
27
|
}
|
|
26
28
|
});
|
|
27
29
|
});
|
|
30
|
+
await ((_this$options$onVerif = (_this$options = this.options).onVerify) == null ? void 0 : _this$options$onVerif.call(_this$options, data));
|
|
31
|
+
return data;
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
async verifyFromHttpHeaders(headers) {
|