@dwtechs/toker-express 0.6.0 → 0.6.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/dist/toker-express.js +9 -7
- package/package.json +1 -1
package/dist/toker-express.js
CHANGED
|
@@ -59,7 +59,7 @@ function createTokens(req, res, next) {
|
|
|
59
59
|
}
|
|
60
60
|
function refreshTokens(req, res, next) {
|
|
61
61
|
var _a, _b, _c;
|
|
62
|
-
|
|
62
|
+
const iss = (_c = (_b = (_a = res.locals) === null || _a === void 0 ? void 0 : _a.tokens) === null || _b === void 0 ? void 0 : _b.decodedAccess) === null || _c === void 0 ? void 0 : _c.iss;
|
|
63
63
|
if (!isValidInteger(iss, 1, 999999999, false))
|
|
64
64
|
return next({ statusCode: 400, message: `${LOGS_PREFIX}Missing iss` });
|
|
65
65
|
log.debug(`${LOGS_PREFIX}Create tokens for user ${iss}`);
|
|
@@ -78,11 +78,12 @@ function refreshTokens(req, res, next) {
|
|
|
78
78
|
next();
|
|
79
79
|
}
|
|
80
80
|
function parseBearer(req, res, next) {
|
|
81
|
-
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (!((_b = (_a = res.locals) === null || _a === void 0 ? void 0 : _a.route) === null || _b === void 0 ? void 0 : _b.isProtected))
|
|
82
83
|
return next();
|
|
83
84
|
log.debug(`${LOGS_PREFIX}parse bearer to get access token`);
|
|
84
85
|
try {
|
|
85
|
-
res.locals.tokens.access
|
|
86
|
+
res.locals.tokens = Object.assign(Object.assign({}, res.locals.tokens), { access: parseBearer$1(req.headers.authorization) });
|
|
86
87
|
}
|
|
87
88
|
catch (e) {
|
|
88
89
|
return next(e);
|
|
@@ -90,10 +91,11 @@ function parseBearer(req, res, next) {
|
|
|
90
91
|
next();
|
|
91
92
|
}
|
|
92
93
|
function decodeAccess(_req, res, next) {
|
|
94
|
+
var _a, _b, _c, _d;
|
|
93
95
|
log.debug(`${LOGS_PREFIX}decode access token`);
|
|
94
|
-
if (!res.locals.route.isProtected)
|
|
96
|
+
if (!((_b = (_a = res.locals) === null || _a === void 0 ? void 0 : _a.route) === null || _b === void 0 ? void 0 : _b.isProtected))
|
|
95
97
|
return next();
|
|
96
|
-
const t = res.locals.tokens.access;
|
|
98
|
+
const t = (_d = (_c = res.locals) === null || _c === void 0 ? void 0 : _c.tokens) === null || _d === void 0 ? void 0 : _d.access;
|
|
97
99
|
if (!isJWT(t))
|
|
98
100
|
return next({ statusCode: 401, message: `${LOGS_PREFIX}Invalid access token` });
|
|
99
101
|
let dt = null;
|
|
@@ -106,7 +108,7 @@ function decodeAccess(_req, res, next) {
|
|
|
106
108
|
if (!isValidInteger(dt.iss, 1, 999999999, false))
|
|
107
109
|
return next({ statusCode: 400, message: `${LOGS_PREFIX}Missing iss` });
|
|
108
110
|
log.debug(`${LOGS_PREFIX}Decoded access token : ${JSON.stringify(dt)}`);
|
|
109
|
-
res.locals.tokens.decodedAccess
|
|
111
|
+
res.locals.tokens = Object.assign(Object.assign({}, res.locals.tokens), { decodedAccess: dt });
|
|
110
112
|
next();
|
|
111
113
|
}
|
|
112
114
|
function decodeRefresh(req, res, next) {
|
|
@@ -125,7 +127,7 @@ function decodeRefresh(req, res, next) {
|
|
|
125
127
|
if (!isValidInteger(dt.iss, 1, 999999999, false))
|
|
126
128
|
return next({ statusCode: 400, message: `${LOGS_PREFIX}Missing iss` });
|
|
127
129
|
log.debug(`${LOGS_PREFIX}Decoded refresh token : ${JSON.stringify(dt)}`);
|
|
128
|
-
res.locals.tokens.decodedRefresh
|
|
130
|
+
res.locals.tokens = Object.assign(Object.assign({}, res.locals.tokens), { decodedRefresh: dt });
|
|
129
131
|
next();
|
|
130
132
|
}
|
|
131
133
|
|