@dwtechs/toker-express 0.5.1 → 0.5.2
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/README.md +14 -14
- package/dist/toker-express.d.ts +0 -6
- package/dist/toker-express.js +6 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
[](https://opensource.org/licenses/MIT)
|
|
3
3
|
[](https://www.npmjs.com/package/@dwtechs/toker-express)
|
|
4
4
|
[](https://www.npmjs.com/package/@dwtechs/toker-express)
|
|
5
|
-

|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
- [Synopsis](#synopsis)
|
|
@@ -47,7 +47,7 @@ $ npm i @dwtechs/toker-express
|
|
|
47
47
|
```javascript
|
|
48
48
|
|
|
49
49
|
// @ts-check
|
|
50
|
-
import
|
|
50
|
+
import * as tk from "@dwtechs/toker-express";
|
|
51
51
|
import express from "express";
|
|
52
52
|
const router = express.Router();
|
|
53
53
|
|
|
@@ -66,18 +66,18 @@ const add = [
|
|
|
66
66
|
|
|
67
67
|
const refresh = [
|
|
68
68
|
cEntity.validate,
|
|
69
|
-
parseBearerToken,
|
|
70
|
-
decodeAccess,
|
|
71
|
-
decodeRefresh,
|
|
69
|
+
tk.parseBearerToken,
|
|
70
|
+
tk.decodeAccess,
|
|
71
|
+
tk.decodeRefresh,
|
|
72
72
|
checkToken,
|
|
73
|
-
refresh,
|
|
73
|
+
tk.refresh,
|
|
74
74
|
cEntity.update,
|
|
75
75
|
];
|
|
76
76
|
|
|
77
77
|
const del = [
|
|
78
78
|
checkToken,
|
|
79
|
-
parseBearerToken,
|
|
80
|
-
decodeAccess,
|
|
79
|
+
tk.parseBearerToken,
|
|
80
|
+
tk.decodeAccess,
|
|
81
81
|
cEntity.delete,
|
|
82
82
|
];
|
|
83
83
|
|
|
@@ -244,17 +244,17 @@ if (!iss)
|
|
|
244
244
|
iss = res.locals.id ?? null;
|
|
245
245
|
```
|
|
246
246
|
|
|
247
|
-
It will then send both new refresh and access tokens in the res.locals object and
|
|
247
|
+
It will then send both new refresh and access tokens in the res.locals object and in req.body.rows[0].
|
|
248
|
+
|
|
249
|
+
**Note:** If `req.body.rows` doesn't exist or is not an array, it will be automatically created as `[{}]`. If `req.body.rows[0]` is not an object, it will be replaced with `{}`.
|
|
248
250
|
|
|
249
251
|
```Javascript
|
|
250
252
|
res.locals.accessToken = accessToken;
|
|
251
253
|
res.locals.refreshToken = refreshToken;
|
|
252
254
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
rbr[0].refreshToken = refreshToken;
|
|
257
|
-
}
|
|
255
|
+
// req.body.rows is automatically created if needed
|
|
256
|
+
req.body.rows[0].accessToken = accessToken;
|
|
257
|
+
req.body.rows[0].refreshToken = refreshToken;
|
|
258
258
|
```
|
|
259
259
|
|
|
260
260
|
### JWT Decoding
|
package/dist/toker-express.d.ts
CHANGED
|
@@ -26,12 +26,6 @@ https://github.com/DWTechs/Toker-express.js
|
|
|
26
26
|
|
|
27
27
|
import type { Request, Response, NextFunction } from 'express';
|
|
28
28
|
|
|
29
|
-
export interface RowWithTokens {
|
|
30
|
-
accessToken?: string;
|
|
31
|
-
refreshToken?: string;
|
|
32
|
-
[key: string]: any;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
29
|
declare function refresh(req: Request, res: Response, next: NextFunction): void;
|
|
36
30
|
declare function parseBearerToken(req: Request, res: Response, next: NextFunction): void;
|
|
37
31
|
declare function decodeAccess(_req: Request, res: Response, next: NextFunction): void;
|
package/dist/toker-express.js
CHANGED
|
@@ -57,11 +57,12 @@ function refresh(req, res, next) {
|
|
|
57
57
|
log.debug(`refreshToken='${rt}', accessToken='${at}'`);
|
|
58
58
|
res.locals.accessToken = at;
|
|
59
59
|
res.locals.refreshToken = rt;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
if (!isArray((_d = req.body) === null || _d === void 0 ? void 0 : _d.rows, ">=", 1))
|
|
61
|
+
req.body.rows = [{}];
|
|
62
|
+
else if (!isObject(req.body.rows[0]))
|
|
63
|
+
req.body.rows[0] = {};
|
|
64
|
+
req.body.rows[0].accessToken = at;
|
|
65
|
+
req.body.rows[0].refreshToken = rt;
|
|
65
66
|
next();
|
|
66
67
|
}
|
|
67
68
|
function parseBearerToken(req, res, next) {
|