dauth-md-node 0.1.2 → 0.1.4
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/dauth-md-node.cjs.development.js +27 -380
- package/dist/dauth-md-node.cjs.development.js.map +1 -1
- package/dist/dauth-md-node.cjs.production.min.js +1 -1
- package/dist/dauth-md-node.cjs.production.min.js.map +1 -1
- package/dist/dauth-md-node.esm.js +27 -380
- package/dist/dauth-md-node.esm.js.map +1 -1
- package/dist/index.d.ts +5 -5
- package/package.json +1 -1
- package/src/index.ts +5 -5
|
@@ -6,395 +6,42 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
|
|
|
6
6
|
|
|
7
7
|
var jwt = _interopDefault(require('jsonwebtoken'));
|
|
8
8
|
|
|
9
|
-
function
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
n = r.hasOwnProperty,
|
|
17
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
18
|
-
t[e] = r.value;
|
|
19
|
-
},
|
|
20
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
21
|
-
a = i.iterator || "@@iterator",
|
|
22
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
23
|
-
u = i.toStringTag || "@@toStringTag";
|
|
24
|
-
function define(t, e, r) {
|
|
25
|
-
return Object.defineProperty(t, e, {
|
|
26
|
-
value: r,
|
|
27
|
-
enumerable: !0,
|
|
28
|
-
configurable: !0,
|
|
29
|
-
writable: !0
|
|
30
|
-
}), t[e];
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
define({}, "");
|
|
34
|
-
} catch (t) {
|
|
35
|
-
define = function (t, e, r) {
|
|
36
|
-
return t[e] = r;
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
function wrap(t, e, r, n) {
|
|
40
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
41
|
-
a = Object.create(i.prototype),
|
|
42
|
-
c = new Context(n || []);
|
|
43
|
-
return o(a, "_invoke", {
|
|
44
|
-
value: makeInvokeMethod(t, r, c)
|
|
45
|
-
}), a;
|
|
46
|
-
}
|
|
47
|
-
function tryCatch(t, e, r) {
|
|
48
|
-
try {
|
|
49
|
-
return {
|
|
50
|
-
type: "normal",
|
|
51
|
-
arg: t.call(e, r)
|
|
52
|
-
};
|
|
53
|
-
} catch (t) {
|
|
54
|
-
return {
|
|
55
|
-
type: "throw",
|
|
56
|
-
arg: t
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
e.wrap = wrap;
|
|
61
|
-
var h = "suspendedStart",
|
|
62
|
-
l = "suspendedYield",
|
|
63
|
-
f = "executing",
|
|
64
|
-
s = "completed",
|
|
65
|
-
y = {};
|
|
66
|
-
function Generator() {}
|
|
67
|
-
function GeneratorFunction() {}
|
|
68
|
-
function GeneratorFunctionPrototype() {}
|
|
69
|
-
var p = {};
|
|
70
|
-
define(p, a, function () {
|
|
71
|
-
return this;
|
|
72
|
-
});
|
|
73
|
-
var d = Object.getPrototypeOf,
|
|
74
|
-
v = d && d(d(values([])));
|
|
75
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
76
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
77
|
-
function defineIteratorMethods(t) {
|
|
78
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
79
|
-
define(t, e, function (t) {
|
|
80
|
-
return this._invoke(e, t);
|
|
9
|
+
var dauth = function dauth(_ref) {
|
|
10
|
+
var ssid = _ref.ssid;
|
|
11
|
+
return function (req, res, next) {
|
|
12
|
+
if (!req.headers.authorization) {
|
|
13
|
+
return res.status(403).send({
|
|
14
|
+
status: 'token-not-found',
|
|
15
|
+
mdKey: 'ensure_auth'
|
|
81
16
|
});
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
function AsyncIterator(t, e) {
|
|
85
|
-
function invoke(r, o, i, a) {
|
|
86
|
-
var c = tryCatch(t[r], t, o);
|
|
87
|
-
if ("throw" !== c.type) {
|
|
88
|
-
var u = c.arg,
|
|
89
|
-
h = u.value;
|
|
90
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
91
|
-
invoke("next", t, i, a);
|
|
92
|
-
}, function (t) {
|
|
93
|
-
invoke("throw", t, i, a);
|
|
94
|
-
}) : e.resolve(h).then(function (t) {
|
|
95
|
-
u.value = t, i(u);
|
|
96
|
-
}, function (t) {
|
|
97
|
-
return invoke("throw", t, i, a);
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
a(c.arg);
|
|
101
17
|
}
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
var o = h;
|
|
116
|
-
return function (i, a) {
|
|
117
|
-
if (o === f) throw new Error("Generator is already running");
|
|
118
|
-
if (o === s) {
|
|
119
|
-
if ("throw" === i) throw a;
|
|
120
|
-
return {
|
|
121
|
-
value: t,
|
|
122
|
-
done: !0
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
for (n.method = i, n.arg = a;;) {
|
|
126
|
-
var c = n.delegate;
|
|
127
|
-
if (c) {
|
|
128
|
-
var u = maybeInvokeDelegate(c, n);
|
|
129
|
-
if (u) {
|
|
130
|
-
if (u === y) continue;
|
|
131
|
-
return u;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
135
|
-
if (o === h) throw o = s, n.arg;
|
|
136
|
-
n.dispatchException(n.arg);
|
|
137
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
138
|
-
o = f;
|
|
139
|
-
var p = tryCatch(e, r, n);
|
|
140
|
-
if ("normal" === p.type) {
|
|
141
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
142
|
-
return {
|
|
143
|
-
value: p.arg,
|
|
144
|
-
done: n.done
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function maybeInvokeDelegate(e, r) {
|
|
152
|
-
var n = r.method,
|
|
153
|
-
o = e.iterator[n];
|
|
154
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
155
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
156
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
157
|
-
var a = i.arg;
|
|
158
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
159
|
-
}
|
|
160
|
-
function pushTryEntry(t) {
|
|
161
|
-
var e = {
|
|
162
|
-
tryLoc: t[0]
|
|
163
|
-
};
|
|
164
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
165
|
-
}
|
|
166
|
-
function resetTryEntry(t) {
|
|
167
|
-
var e = t.completion || {};
|
|
168
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
169
|
-
}
|
|
170
|
-
function Context(t) {
|
|
171
|
-
this.tryEntries = [{
|
|
172
|
-
tryLoc: "root"
|
|
173
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
174
|
-
}
|
|
175
|
-
function values(e) {
|
|
176
|
-
if (e || "" === e) {
|
|
177
|
-
var r = e[a];
|
|
178
|
-
if (r) return r.call(e);
|
|
179
|
-
if ("function" == typeof e.next) return e;
|
|
180
|
-
if (!isNaN(e.length)) {
|
|
181
|
-
var o = -1,
|
|
182
|
-
i = function next() {
|
|
183
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
184
|
-
return next.value = t, next.done = !0, next;
|
|
185
|
-
};
|
|
186
|
-
return i.next = i;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
190
|
-
}
|
|
191
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
192
|
-
value: GeneratorFunctionPrototype,
|
|
193
|
-
configurable: !0
|
|
194
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
195
|
-
value: GeneratorFunction,
|
|
196
|
-
configurable: !0
|
|
197
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
198
|
-
var e = "function" == typeof t && t.constructor;
|
|
199
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
200
|
-
}, e.mark = function (t) {
|
|
201
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
202
|
-
}, e.awrap = function (t) {
|
|
203
|
-
return {
|
|
204
|
-
__await: t
|
|
205
|
-
};
|
|
206
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
207
|
-
return this;
|
|
208
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
209
|
-
void 0 === i && (i = Promise);
|
|
210
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
211
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
212
|
-
return t.done ? t.value : a.next();
|
|
213
|
-
});
|
|
214
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
215
|
-
return this;
|
|
216
|
-
}), define(g, "toString", function () {
|
|
217
|
-
return "[object Generator]";
|
|
218
|
-
}), e.keys = function (t) {
|
|
219
|
-
var e = Object(t),
|
|
220
|
-
r = [];
|
|
221
|
-
for (var n in e) r.push(n);
|
|
222
|
-
return r.reverse(), function next() {
|
|
223
|
-
for (; r.length;) {
|
|
224
|
-
var t = r.pop();
|
|
225
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
226
|
-
}
|
|
227
|
-
return next.done = !0, next;
|
|
228
|
-
};
|
|
229
|
-
}, e.values = values, Context.prototype = {
|
|
230
|
-
constructor: Context,
|
|
231
|
-
reset: function (e) {
|
|
232
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
233
|
-
},
|
|
234
|
-
stop: function () {
|
|
235
|
-
this.done = !0;
|
|
236
|
-
var t = this.tryEntries[0].completion;
|
|
237
|
-
if ("throw" === t.type) throw t.arg;
|
|
238
|
-
return this.rval;
|
|
239
|
-
},
|
|
240
|
-
dispatchException: function (e) {
|
|
241
|
-
if (this.done) throw e;
|
|
242
|
-
var r = this;
|
|
243
|
-
function handle(n, o) {
|
|
244
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
245
|
-
}
|
|
246
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
247
|
-
var i = this.tryEntries[o],
|
|
248
|
-
a = i.completion;
|
|
249
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
250
|
-
if (i.tryLoc <= this.prev) {
|
|
251
|
-
var c = n.call(i, "catchLoc"),
|
|
252
|
-
u = n.call(i, "finallyLoc");
|
|
253
|
-
if (c && u) {
|
|
254
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
255
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
256
|
-
} else if (c) {
|
|
257
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
258
|
-
} else {
|
|
259
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
260
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
abrupt: function (t, e) {
|
|
266
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
267
|
-
var o = this.tryEntries[r];
|
|
268
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
269
|
-
var i = o;
|
|
270
|
-
break;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
274
|
-
var a = i ? i.completion : {};
|
|
275
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
276
|
-
},
|
|
277
|
-
complete: function (t, e) {
|
|
278
|
-
if ("throw" === t.type) throw t.arg;
|
|
279
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
280
|
-
},
|
|
281
|
-
finish: function (t) {
|
|
282
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
-
var r = this.tryEntries[e];
|
|
284
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
285
|
-
}
|
|
286
|
-
},
|
|
287
|
-
catch: function (t) {
|
|
288
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
289
|
-
var r = this.tryEntries[e];
|
|
290
|
-
if (r.tryLoc === t) {
|
|
291
|
-
var n = r.completion;
|
|
292
|
-
if ("throw" === n.type) {
|
|
293
|
-
var o = n.arg;
|
|
294
|
-
resetTryEntry(r);
|
|
295
|
-
}
|
|
296
|
-
return o;
|
|
297
|
-
}
|
|
18
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
19
|
+
try {
|
|
20
|
+
var payload = jwt.verify(token, ssid);
|
|
21
|
+
req.auth = payload;
|
|
22
|
+
return next();
|
|
23
|
+
} catch (err) {
|
|
24
|
+
if (err && (err == null ? void 0 : err.message) === 'jwt expired') {
|
|
25
|
+
return res.status(500).send({
|
|
26
|
+
status: 'token-expired',
|
|
27
|
+
message: 'El token ha expirado',
|
|
28
|
+
error: err,
|
|
29
|
+
mdKey: 'ensure_auth'
|
|
30
|
+
});
|
|
298
31
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
nextLoc: n
|
|
306
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
32
|
+
return res.status(500).send({
|
|
33
|
+
status: 'token-invalid',
|
|
34
|
+
message: 'El token no es válido',
|
|
35
|
+
error: err,
|
|
36
|
+
mdKey: 'ensure_auth'
|
|
37
|
+
});
|
|
307
38
|
}
|
|
308
|
-
}, e;
|
|
309
|
-
}
|
|
310
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
311
|
-
try {
|
|
312
|
-
var info = gen[key](arg);
|
|
313
|
-
var value = info.value;
|
|
314
|
-
} catch (error) {
|
|
315
|
-
reject(error);
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
if (info.done) {
|
|
319
|
-
resolve(value);
|
|
320
|
-
} else {
|
|
321
|
-
Promise.resolve(value).then(_next, _throw);
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
function _asyncToGenerator(fn) {
|
|
325
|
-
return function () {
|
|
326
|
-
var self = this,
|
|
327
|
-
args = arguments;
|
|
328
|
-
return new Promise(function (resolve, reject) {
|
|
329
|
-
var gen = fn.apply(self, args);
|
|
330
|
-
function _next(value) {
|
|
331
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
332
|
-
}
|
|
333
|
-
function _throw(err) {
|
|
334
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
335
|
-
}
|
|
336
|
-
_next(undefined);
|
|
337
|
-
});
|
|
338
39
|
};
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
var auth = function auth(_ref) {
|
|
342
|
-
var ssid = _ref.ssid;
|
|
343
|
-
return /*#__PURE__*/function () {
|
|
344
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
|
|
345
|
-
var token, payload;
|
|
346
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
347
|
-
while (1) switch (_context.prev = _context.next) {
|
|
348
|
-
case 0:
|
|
349
|
-
if (req.headers.authorization) {
|
|
350
|
-
_context.next = 2;
|
|
351
|
-
break;
|
|
352
|
-
}
|
|
353
|
-
return _context.abrupt("return", res.status(403).send({
|
|
354
|
-
status: 'token-not-found',
|
|
355
|
-
mdKey: 'ensure_auth'
|
|
356
|
-
}));
|
|
357
|
-
case 2:
|
|
358
|
-
token = req.headers.authorization.replace(/['"]+/g, '');
|
|
359
|
-
_context.prev = 3;
|
|
360
|
-
payload = jwt.verify(token, ssid);
|
|
361
|
-
req.auth = payload;
|
|
362
|
-
return _context.abrupt("return", next());
|
|
363
|
-
case 9:
|
|
364
|
-
_context.prev = 9;
|
|
365
|
-
_context.t0 = _context["catch"](3);
|
|
366
|
-
if (!(_context.t0 && (_context.t0 == null ? void 0 : _context.t0.message) === 'jwt expired')) {
|
|
367
|
-
_context.next = 13;
|
|
368
|
-
break;
|
|
369
|
-
}
|
|
370
|
-
return _context.abrupt("return", res.status(500).send({
|
|
371
|
-
status: 'token-expired',
|
|
372
|
-
message: 'El token ha expirado',
|
|
373
|
-
error: _context.t0,
|
|
374
|
-
mdKey: 'ensure_auth'
|
|
375
|
-
}));
|
|
376
|
-
case 13:
|
|
377
|
-
return _context.abrupt("return", res.status(500).send({
|
|
378
|
-
status: 'token-invalid',
|
|
379
|
-
message: 'El token no es válido',
|
|
380
|
-
error: _context.t0,
|
|
381
|
-
mdKey: 'ensure_auth'
|
|
382
|
-
}));
|
|
383
|
-
case 14:
|
|
384
|
-
case "end":
|
|
385
|
-
return _context.stop();
|
|
386
|
-
}
|
|
387
|
-
}, _callee, null, [[3, 9]]);
|
|
388
|
-
}));
|
|
389
|
-
return function (_x, _x2, _x3) {
|
|
390
|
-
return _ref2.apply(this, arguments);
|
|
391
|
-
};
|
|
392
|
-
}();
|
|
393
40
|
};
|
|
394
41
|
var sum = function sum(a, b) {
|
|
395
42
|
return a + b;
|
|
396
43
|
};
|
|
397
44
|
|
|
398
|
-
exports.
|
|
45
|
+
exports.dauth = dauth;
|
|
399
46
|
exports.sum = sum;
|
|
400
47
|
//# sourceMappingURL=dauth-md-node.cjs.development.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.development.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (req: IRequestUser, res: TCustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n\nexport const sum = (a: number, b: number) => a + b;\n"],"names":["dauth","_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","err","message","error","sum","a","b"],"mappings":";;;;;;;;IA+BaA,KAAK,GAAG,SAARA,KAAKA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAC1B,OAAO,UAACC,GAAiB,EAAEC,GAAoB,EAAEC,IAAkB;IACjE,IAAI,CAACF,GAAG,CAACG,OAAO,CAACC,aAAa,EAAE;MAC9B,OAAOH,GAAG,CACPI,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;QAAED,MAAM,EAAE,iBAAiB;QAAEE,KAAK,EAAE;OAAe,CAAC;;IAE9D,IAAMC,KAAK,GAAGR,GAAG,CAACG,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,IAAI;MACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAET,IAAc,CAAiB;MACjEC,GAAG,CAACa,IAAI,GAAGH,OAAO;MAClB,OAAOR,IAAI,EAAE;KACd,CAAC,OAAOY,GAAG,EAAE;MACZ,IAAIA,GAAG,IAAI,CAAAA,GAAG,oBAAHA,GAAG,CAAEC,OAAO,MAAK,aAAa,EAAE;QACzC,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;UAC1BD,MAAM,EAAE,eAAe;UACvBU,OAAO,EAAE,sBAAsB;UAC/BC,KAAK,EAAEF,GAAG;UACVP,KAAK,EAAE;SACR,CAAC;;MAEJ,OAAON,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAC1BD,MAAM,EAAE,eAAe;QACvBU,OAAO,EAAE,uBAAuB;QAChCC,KAAK,EAAEF,GAAG;QACVP,KAAK,EAAE;OACR,CAAC;;GAEL;AACH;IAEaU,GAAG,GAAG,SAANA,GAAGA,CAAIC,CAAS,EAAEC,CAAS;EAAA,OAAKD,CAAC,GAAGC,CAAC;AAAA;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var t
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=(e=require("jsonwebtoken"))&&"object"==typeof e&&"default"in e?e.default:e;exports.dauth=function(e){var r=e.ssid;return function(e,s,n){if(!e.headers.authorization)return s.status(403).send({status:"token-not-found",mdKey:"ensure_auth"});var u=e.headers.authorization.replace(/['"]+/g,"");try{var a=t.verify(u,r);return e.auth=a,n()}catch(e){return e&&"jwt expired"===(null==e?void 0:e.message)?s.status(500).send({status:"token-expired",message:"El token ha expirado",error:e,mdKey:"ensure_auth"}):s.status(500).send({status:"token-invalid",message:"El token no es válido",error:e,mdKey:"ensure_auth"})}}},exports.sum=function(e,t){return e+t};
|
|
2
2
|
//# sourceMappingURL=dauth-md-node.cjs.production.min.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface
|
|
1
|
+
{"version":3,"file":"dauth-md-node.cjs.production.min.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (req: IRequestUser, res: TCustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n\nexport const sum = (a: number, b: number) => a + b;\n"],"names":["_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","err","message","error","a","b"],"mappings":"qKA+BqB,SAAHA,OAAMC,EAAID,EAAJC,KACtB,OAAO,SAACC,EAAmBC,EAAsBC,GAC/C,IAAKF,EAAIG,QAAQC,cACf,OAAOH,EACJI,OAAO,KACPC,KAAK,CAAED,OAAQ,kBAAmBE,MAAO,gBAE9C,IAAMC,EAAQR,EAAIG,QAAQC,cAAcK,QAAQ,SAAU,IAC1D,IACE,IAAMC,EAAUC,EAAIC,OAAOJ,EAAOT,GAElC,OADAC,EAAIa,KAAOH,EACJR,IACP,MAAOY,GACP,OAAIA,GAAwB,uBAAjBA,SAAAA,EAAKC,SACPd,EAAII,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,uBACTC,MAAOF,EACPP,MAAO,gBAGJN,EAAII,OAAO,KAAKC,KAAK,CAC1BD,OAAQ,gBACRU,QAAS,wBACTC,MAAOF,EACPP,MAAO,+BAMI,SAACU,EAAWC,GAAS,OAAKD,EAAIC"}
|
|
@@ -1,393 +1,40 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
n = r.hasOwnProperty,
|
|
11
|
-
o = Object.defineProperty || function (t, e, r) {
|
|
12
|
-
t[e] = r.value;
|
|
13
|
-
},
|
|
14
|
-
i = "function" == typeof Symbol ? Symbol : {},
|
|
15
|
-
a = i.iterator || "@@iterator",
|
|
16
|
-
c = i.asyncIterator || "@@asyncIterator",
|
|
17
|
-
u = i.toStringTag || "@@toStringTag";
|
|
18
|
-
function define(t, e, r) {
|
|
19
|
-
return Object.defineProperty(t, e, {
|
|
20
|
-
value: r,
|
|
21
|
-
enumerable: !0,
|
|
22
|
-
configurable: !0,
|
|
23
|
-
writable: !0
|
|
24
|
-
}), t[e];
|
|
25
|
-
}
|
|
26
|
-
try {
|
|
27
|
-
define({}, "");
|
|
28
|
-
} catch (t) {
|
|
29
|
-
define = function (t, e, r) {
|
|
30
|
-
return t[e] = r;
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function wrap(t, e, r, n) {
|
|
34
|
-
var i = e && e.prototype instanceof Generator ? e : Generator,
|
|
35
|
-
a = Object.create(i.prototype),
|
|
36
|
-
c = new Context(n || []);
|
|
37
|
-
return o(a, "_invoke", {
|
|
38
|
-
value: makeInvokeMethod(t, r, c)
|
|
39
|
-
}), a;
|
|
40
|
-
}
|
|
41
|
-
function tryCatch(t, e, r) {
|
|
42
|
-
try {
|
|
43
|
-
return {
|
|
44
|
-
type: "normal",
|
|
45
|
-
arg: t.call(e, r)
|
|
46
|
-
};
|
|
47
|
-
} catch (t) {
|
|
48
|
-
return {
|
|
49
|
-
type: "throw",
|
|
50
|
-
arg: t
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
e.wrap = wrap;
|
|
55
|
-
var h = "suspendedStart",
|
|
56
|
-
l = "suspendedYield",
|
|
57
|
-
f = "executing",
|
|
58
|
-
s = "completed",
|
|
59
|
-
y = {};
|
|
60
|
-
function Generator() {}
|
|
61
|
-
function GeneratorFunction() {}
|
|
62
|
-
function GeneratorFunctionPrototype() {}
|
|
63
|
-
var p = {};
|
|
64
|
-
define(p, a, function () {
|
|
65
|
-
return this;
|
|
66
|
-
});
|
|
67
|
-
var d = Object.getPrototypeOf,
|
|
68
|
-
v = d && d(d(values([])));
|
|
69
|
-
v && v !== r && n.call(v, a) && (p = v);
|
|
70
|
-
var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
|
|
71
|
-
function defineIteratorMethods(t) {
|
|
72
|
-
["next", "throw", "return"].forEach(function (e) {
|
|
73
|
-
define(t, e, function (t) {
|
|
74
|
-
return this._invoke(e, t);
|
|
3
|
+
var dauth = function dauth(_ref) {
|
|
4
|
+
var ssid = _ref.ssid;
|
|
5
|
+
return function (req, res, next) {
|
|
6
|
+
if (!req.headers.authorization) {
|
|
7
|
+
return res.status(403).send({
|
|
8
|
+
status: 'token-not-found',
|
|
9
|
+
mdKey: 'ensure_auth'
|
|
75
10
|
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function AsyncIterator(t, e) {
|
|
79
|
-
function invoke(r, o, i, a) {
|
|
80
|
-
var c = tryCatch(t[r], t, o);
|
|
81
|
-
if ("throw" !== c.type) {
|
|
82
|
-
var u = c.arg,
|
|
83
|
-
h = u.value;
|
|
84
|
-
return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
|
|
85
|
-
invoke("next", t, i, a);
|
|
86
|
-
}, function (t) {
|
|
87
|
-
invoke("throw", t, i, a);
|
|
88
|
-
}) : e.resolve(h).then(function (t) {
|
|
89
|
-
u.value = t, i(u);
|
|
90
|
-
}, function (t) {
|
|
91
|
-
return invoke("throw", t, i, a);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
a(c.arg);
|
|
95
11
|
}
|
|
96
|
-
var
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
var o = h;
|
|
110
|
-
return function (i, a) {
|
|
111
|
-
if (o === f) throw new Error("Generator is already running");
|
|
112
|
-
if (o === s) {
|
|
113
|
-
if ("throw" === i) throw a;
|
|
114
|
-
return {
|
|
115
|
-
value: t,
|
|
116
|
-
done: !0
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
for (n.method = i, n.arg = a;;) {
|
|
120
|
-
var c = n.delegate;
|
|
121
|
-
if (c) {
|
|
122
|
-
var u = maybeInvokeDelegate(c, n);
|
|
123
|
-
if (u) {
|
|
124
|
-
if (u === y) continue;
|
|
125
|
-
return u;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
|
|
129
|
-
if (o === h) throw o = s, n.arg;
|
|
130
|
-
n.dispatchException(n.arg);
|
|
131
|
-
} else "return" === n.method && n.abrupt("return", n.arg);
|
|
132
|
-
o = f;
|
|
133
|
-
var p = tryCatch(e, r, n);
|
|
134
|
-
if ("normal" === p.type) {
|
|
135
|
-
if (o = n.done ? s : l, p.arg === y) continue;
|
|
136
|
-
return {
|
|
137
|
-
value: p.arg,
|
|
138
|
-
done: n.done
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
"throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
function maybeInvokeDelegate(e, r) {
|
|
146
|
-
var n = r.method,
|
|
147
|
-
o = e.iterator[n];
|
|
148
|
-
if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
|
|
149
|
-
var i = tryCatch(o, e.iterator, r.arg);
|
|
150
|
-
if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
|
|
151
|
-
var a = i.arg;
|
|
152
|
-
return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
|
|
153
|
-
}
|
|
154
|
-
function pushTryEntry(t) {
|
|
155
|
-
var e = {
|
|
156
|
-
tryLoc: t[0]
|
|
157
|
-
};
|
|
158
|
-
1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
|
|
159
|
-
}
|
|
160
|
-
function resetTryEntry(t) {
|
|
161
|
-
var e = t.completion || {};
|
|
162
|
-
e.type = "normal", delete e.arg, t.completion = e;
|
|
163
|
-
}
|
|
164
|
-
function Context(t) {
|
|
165
|
-
this.tryEntries = [{
|
|
166
|
-
tryLoc: "root"
|
|
167
|
-
}], t.forEach(pushTryEntry, this), this.reset(!0);
|
|
168
|
-
}
|
|
169
|
-
function values(e) {
|
|
170
|
-
if (e || "" === e) {
|
|
171
|
-
var r = e[a];
|
|
172
|
-
if (r) return r.call(e);
|
|
173
|
-
if ("function" == typeof e.next) return e;
|
|
174
|
-
if (!isNaN(e.length)) {
|
|
175
|
-
var o = -1,
|
|
176
|
-
i = function next() {
|
|
177
|
-
for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
|
|
178
|
-
return next.value = t, next.done = !0, next;
|
|
179
|
-
};
|
|
180
|
-
return i.next = i;
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
throw new TypeError(typeof e + " is not iterable");
|
|
184
|
-
}
|
|
185
|
-
return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
|
|
186
|
-
value: GeneratorFunctionPrototype,
|
|
187
|
-
configurable: !0
|
|
188
|
-
}), o(GeneratorFunctionPrototype, "constructor", {
|
|
189
|
-
value: GeneratorFunction,
|
|
190
|
-
configurable: !0
|
|
191
|
-
}), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
|
|
192
|
-
var e = "function" == typeof t && t.constructor;
|
|
193
|
-
return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
|
|
194
|
-
}, e.mark = function (t) {
|
|
195
|
-
return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
|
|
196
|
-
}, e.awrap = function (t) {
|
|
197
|
-
return {
|
|
198
|
-
__await: t
|
|
199
|
-
};
|
|
200
|
-
}, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
|
|
201
|
-
return this;
|
|
202
|
-
}), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
|
|
203
|
-
void 0 === i && (i = Promise);
|
|
204
|
-
var a = new AsyncIterator(wrap(t, r, n, o), i);
|
|
205
|
-
return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
|
|
206
|
-
return t.done ? t.value : a.next();
|
|
207
|
-
});
|
|
208
|
-
}, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
|
|
209
|
-
return this;
|
|
210
|
-
}), define(g, "toString", function () {
|
|
211
|
-
return "[object Generator]";
|
|
212
|
-
}), e.keys = function (t) {
|
|
213
|
-
var e = Object(t),
|
|
214
|
-
r = [];
|
|
215
|
-
for (var n in e) r.push(n);
|
|
216
|
-
return r.reverse(), function next() {
|
|
217
|
-
for (; r.length;) {
|
|
218
|
-
var t = r.pop();
|
|
219
|
-
if (t in e) return next.value = t, next.done = !1, next;
|
|
220
|
-
}
|
|
221
|
-
return next.done = !0, next;
|
|
222
|
-
};
|
|
223
|
-
}, e.values = values, Context.prototype = {
|
|
224
|
-
constructor: Context,
|
|
225
|
-
reset: function (e) {
|
|
226
|
-
if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
|
|
227
|
-
},
|
|
228
|
-
stop: function () {
|
|
229
|
-
this.done = !0;
|
|
230
|
-
var t = this.tryEntries[0].completion;
|
|
231
|
-
if ("throw" === t.type) throw t.arg;
|
|
232
|
-
return this.rval;
|
|
233
|
-
},
|
|
234
|
-
dispatchException: function (e) {
|
|
235
|
-
if (this.done) throw e;
|
|
236
|
-
var r = this;
|
|
237
|
-
function handle(n, o) {
|
|
238
|
-
return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
|
|
239
|
-
}
|
|
240
|
-
for (var o = this.tryEntries.length - 1; o >= 0; --o) {
|
|
241
|
-
var i = this.tryEntries[o],
|
|
242
|
-
a = i.completion;
|
|
243
|
-
if ("root" === i.tryLoc) return handle("end");
|
|
244
|
-
if (i.tryLoc <= this.prev) {
|
|
245
|
-
var c = n.call(i, "catchLoc"),
|
|
246
|
-
u = n.call(i, "finallyLoc");
|
|
247
|
-
if (c && u) {
|
|
248
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
249
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
250
|
-
} else if (c) {
|
|
251
|
-
if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
|
|
252
|
-
} else {
|
|
253
|
-
if (!u) throw new Error("try statement without catch or finally");
|
|
254
|
-
if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
},
|
|
259
|
-
abrupt: function (t, e) {
|
|
260
|
-
for (var r = this.tryEntries.length - 1; r >= 0; --r) {
|
|
261
|
-
var o = this.tryEntries[r];
|
|
262
|
-
if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
|
|
263
|
-
var i = o;
|
|
264
|
-
break;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
|
|
268
|
-
var a = i ? i.completion : {};
|
|
269
|
-
return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
|
|
270
|
-
},
|
|
271
|
-
complete: function (t, e) {
|
|
272
|
-
if ("throw" === t.type) throw t.arg;
|
|
273
|
-
return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
|
|
274
|
-
},
|
|
275
|
-
finish: function (t) {
|
|
276
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
277
|
-
var r = this.tryEntries[e];
|
|
278
|
-
if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
|
|
279
|
-
}
|
|
280
|
-
},
|
|
281
|
-
catch: function (t) {
|
|
282
|
-
for (var e = this.tryEntries.length - 1; e >= 0; --e) {
|
|
283
|
-
var r = this.tryEntries[e];
|
|
284
|
-
if (r.tryLoc === t) {
|
|
285
|
-
var n = r.completion;
|
|
286
|
-
if ("throw" === n.type) {
|
|
287
|
-
var o = n.arg;
|
|
288
|
-
resetTryEntry(r);
|
|
289
|
-
}
|
|
290
|
-
return o;
|
|
291
|
-
}
|
|
12
|
+
var token = req.headers.authorization.replace(/['"]+/g, '');
|
|
13
|
+
try {
|
|
14
|
+
var payload = jwt.verify(token, ssid);
|
|
15
|
+
req.auth = payload;
|
|
16
|
+
return next();
|
|
17
|
+
} catch (err) {
|
|
18
|
+
if (err && (err == null ? void 0 : err.message) === 'jwt expired') {
|
|
19
|
+
return res.status(500).send({
|
|
20
|
+
status: 'token-expired',
|
|
21
|
+
message: 'El token ha expirado',
|
|
22
|
+
error: err,
|
|
23
|
+
mdKey: 'ensure_auth'
|
|
24
|
+
});
|
|
292
25
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
nextLoc: n
|
|
300
|
-
}, "next" === this.method && (this.arg = t), y;
|
|
26
|
+
return res.status(500).send({
|
|
27
|
+
status: 'token-invalid',
|
|
28
|
+
message: 'El token no es válido',
|
|
29
|
+
error: err,
|
|
30
|
+
mdKey: 'ensure_auth'
|
|
31
|
+
});
|
|
301
32
|
}
|
|
302
|
-
}, e;
|
|
303
|
-
}
|
|
304
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
305
|
-
try {
|
|
306
|
-
var info = gen[key](arg);
|
|
307
|
-
var value = info.value;
|
|
308
|
-
} catch (error) {
|
|
309
|
-
reject(error);
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (info.done) {
|
|
313
|
-
resolve(value);
|
|
314
|
-
} else {
|
|
315
|
-
Promise.resolve(value).then(_next, _throw);
|
|
316
|
-
}
|
|
317
|
-
}
|
|
318
|
-
function _asyncToGenerator(fn) {
|
|
319
|
-
return function () {
|
|
320
|
-
var self = this,
|
|
321
|
-
args = arguments;
|
|
322
|
-
return new Promise(function (resolve, reject) {
|
|
323
|
-
var gen = fn.apply(self, args);
|
|
324
|
-
function _next(value) {
|
|
325
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
326
|
-
}
|
|
327
|
-
function _throw(err) {
|
|
328
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
329
|
-
}
|
|
330
|
-
_next(undefined);
|
|
331
|
-
});
|
|
332
33
|
};
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
var auth = function auth(_ref) {
|
|
336
|
-
var ssid = _ref.ssid;
|
|
337
|
-
return /*#__PURE__*/function () {
|
|
338
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
|
|
339
|
-
var token, payload;
|
|
340
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
341
|
-
while (1) switch (_context.prev = _context.next) {
|
|
342
|
-
case 0:
|
|
343
|
-
if (req.headers.authorization) {
|
|
344
|
-
_context.next = 2;
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
return _context.abrupt("return", res.status(403).send({
|
|
348
|
-
status: 'token-not-found',
|
|
349
|
-
mdKey: 'ensure_auth'
|
|
350
|
-
}));
|
|
351
|
-
case 2:
|
|
352
|
-
token = req.headers.authorization.replace(/['"]+/g, '');
|
|
353
|
-
_context.prev = 3;
|
|
354
|
-
payload = jwt.verify(token, ssid);
|
|
355
|
-
req.auth = payload;
|
|
356
|
-
return _context.abrupt("return", next());
|
|
357
|
-
case 9:
|
|
358
|
-
_context.prev = 9;
|
|
359
|
-
_context.t0 = _context["catch"](3);
|
|
360
|
-
if (!(_context.t0 && (_context.t0 == null ? void 0 : _context.t0.message) === 'jwt expired')) {
|
|
361
|
-
_context.next = 13;
|
|
362
|
-
break;
|
|
363
|
-
}
|
|
364
|
-
return _context.abrupt("return", res.status(500).send({
|
|
365
|
-
status: 'token-expired',
|
|
366
|
-
message: 'El token ha expirado',
|
|
367
|
-
error: _context.t0,
|
|
368
|
-
mdKey: 'ensure_auth'
|
|
369
|
-
}));
|
|
370
|
-
case 13:
|
|
371
|
-
return _context.abrupt("return", res.status(500).send({
|
|
372
|
-
status: 'token-invalid',
|
|
373
|
-
message: 'El token no es válido',
|
|
374
|
-
error: _context.t0,
|
|
375
|
-
mdKey: 'ensure_auth'
|
|
376
|
-
}));
|
|
377
|
-
case 14:
|
|
378
|
-
case "end":
|
|
379
|
-
return _context.stop();
|
|
380
|
-
}
|
|
381
|
-
}, _callee, null, [[3, 9]]);
|
|
382
|
-
}));
|
|
383
|
-
return function (_x, _x2, _x3) {
|
|
384
|
-
return _ref2.apply(this, arguments);
|
|
385
|
-
};
|
|
386
|
-
}();
|
|
387
34
|
};
|
|
388
35
|
var sum = function sum(a, b) {
|
|
389
36
|
return a + b;
|
|
390
37
|
};
|
|
391
38
|
|
|
392
|
-
export {
|
|
39
|
+
export { dauth, sum };
|
|
393
40
|
//# sourceMappingURL=dauth-md-node.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dauth-md-node.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface
|
|
1
|
+
{"version":3,"file":"dauth-md-node.esm.js","sources":["../src/index.ts"],"sourcesContent":["import { Request, NextFunction, Response as ExpressResponse } from 'express';\nimport mongoose from 'mongoose';\nimport jwt from 'jsonwebtoken';\n\nexport interface IAccessToken {\n _id: string | mongoose.Types.ObjectId;\n sid: string;\n name: string;\n lastname: string;\n email: string;\n createToken?: number;\n exp?: number;\n iat?: number;\n}\n\ninterface IRequestUser extends Request {\n auth: IAccessToken;\n files: {\n image: { path: string };\n avatar: { path: string };\n };\n headers: {\n authorization: string;\n };\n}\n\ninterface TCustomResponse extends ExpressResponse {\n status(code: number): any;\n send(body?: any): any;\n}\n\nexport const dauth = ({ ssid }: { ssid: string }) => {\n return (req: IRequestUser, res: TCustomResponse, next: NextFunction) => {\n if (!req.headers.authorization) {\n return res\n .status(403)\n .send({ status: 'token-not-found', mdKey: 'ensure_auth' });\n }\n const token = req.headers.authorization.replace(/['\"]+/g, '');\n try {\n const payload = jwt.verify(token, ssid as string) as IAccessToken;\n req.auth = payload;\n return next();\n } catch (err) {\n if (err && err?.message === 'jwt expired') {\n return res.status(500).send({\n status: 'token-expired',\n message: 'El token ha expirado',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n return res.status(500).send({\n status: 'token-invalid',\n message: 'El token no es válido',\n error: err,\n mdKey: 'ensure_auth',\n });\n }\n };\n};\n\nexport const sum = (a: number, b: number) => a + b;\n"],"names":["dauth","_ref","ssid","req","res","next","headers","authorization","status","send","mdKey","token","replace","payload","jwt","verify","auth","err","message","error","sum","a","b"],"mappings":";;IA+BaA,KAAK,GAAG,SAARA,KAAKA,CAAAC,IAAA;MAAMC,IAAI,GAAAD,IAAA,CAAJC,IAAI;EAC1B,OAAO,UAACC,GAAiB,EAAEC,GAAoB,EAAEC,IAAkB;IACjE,IAAI,CAACF,GAAG,CAACG,OAAO,CAACC,aAAa,EAAE;MAC9B,OAAOH,GAAG,CACPI,MAAM,CAAC,GAAG,CAAC,CACXC,IAAI,CAAC;QAAED,MAAM,EAAE,iBAAiB;QAAEE,KAAK,EAAE;OAAe,CAAC;;IAE9D,IAAMC,KAAK,GAAGR,GAAG,CAACG,OAAO,CAACC,aAAa,CAACK,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC;IAC7D,IAAI;MACF,IAAMC,OAAO,GAAGC,GAAG,CAACC,MAAM,CAACJ,KAAK,EAAET,IAAc,CAAiB;MACjEC,GAAG,CAACa,IAAI,GAAGH,OAAO;MAClB,OAAOR,IAAI,EAAE;KACd,CAAC,OAAOY,GAAG,EAAE;MACZ,IAAIA,GAAG,IAAI,CAAAA,GAAG,oBAAHA,GAAG,CAAEC,OAAO,MAAK,aAAa,EAAE;QACzC,OAAOd,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;UAC1BD,MAAM,EAAE,eAAe;UACvBU,OAAO,EAAE,sBAAsB;UAC/BC,KAAK,EAAEF,GAAG;UACVP,KAAK,EAAE;SACR,CAAC;;MAEJ,OAAON,GAAG,CAACI,MAAM,CAAC,GAAG,CAAC,CAACC,IAAI,CAAC;QAC1BD,MAAM,EAAE,eAAe;QACvBU,OAAO,EAAE,uBAAuB;QAChCC,KAAK,EAAEF,GAAG;QACVP,KAAK,EAAE;OACR,CAAC;;GAEL;AACH;IAEaU,GAAG,GAAG,SAANA,GAAGA,CAAIC,CAAS,EAAEC,CAAS;EAAA,OAAKD,CAAC,GAAGC,CAAC;AAAA;;;;"}
|
package/dist/index.d.ts
CHANGED
|
@@ -24,12 +24,12 @@ interface IRequestUser extends Request {
|
|
|
24
24
|
authorization: string;
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
|
-
interface
|
|
28
|
-
status(code: number):
|
|
29
|
-
send(body?: any):
|
|
27
|
+
interface TCustomResponse extends ExpressResponse {
|
|
28
|
+
status(code: number): any;
|
|
29
|
+
send(body?: any): any;
|
|
30
30
|
}
|
|
31
|
-
export declare const
|
|
31
|
+
export declare const dauth: ({ ssid }: {
|
|
32
32
|
ssid: string;
|
|
33
|
-
}) => (req: IRequestUser, res:
|
|
33
|
+
}) => (req: IRequestUser, res: TCustomResponse, next: NextFunction) => any;
|
|
34
34
|
export declare const sum: (a: number, b: number) => number;
|
|
35
35
|
export {};
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -24,13 +24,13 @@ interface IRequestUser extends Request {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
interface
|
|
28
|
-
status(code: number):
|
|
29
|
-
send(body?: any):
|
|
27
|
+
interface TCustomResponse extends ExpressResponse {
|
|
28
|
+
status(code: number): any;
|
|
29
|
+
send(body?: any): any;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
export const
|
|
33
|
-
return
|
|
32
|
+
export const dauth = ({ ssid }: { ssid: string }) => {
|
|
33
|
+
return (req: IRequestUser, res: TCustomResponse, next: NextFunction) => {
|
|
34
34
|
if (!req.headers.authorization) {
|
|
35
35
|
return res
|
|
36
36
|
.status(403)
|