dauth-context-react 1.0.2 → 2.0.0

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.
@@ -7,350 +7,147 @@ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'defau
7
7
  var React = require('react');
8
8
  var React__default = _interopDefault(React);
9
9
 
10
- function _regeneratorRuntime() {
11
- _regeneratorRuntime = function () {
12
- return e;
13
- };
14
- var t,
15
- e = {},
16
- r = Object.prototype,
17
- n = r.hasOwnProperty,
18
- o = Object.defineProperty || function (t, e, r) {
19
- t[e] = r.value;
20
- },
21
- i = "function" == typeof Symbol ? Symbol : {},
22
- a = i.iterator || "@@iterator",
23
- c = i.asyncIterator || "@@asyncIterator",
24
- u = i.toStringTag || "@@toStringTag";
25
- function define(t, e, r) {
26
- return Object.defineProperty(t, e, {
27
- value: r,
28
- enumerable: !0,
29
- configurable: !0,
30
- writable: !0
31
- }), t[e];
32
- }
10
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
33
11
  try {
34
- define({}, "");
35
- } catch (t) {
36
- define = function (t, e, r) {
37
- return t[e] = r;
38
- };
39
- }
40
- function wrap(t, e, r, n) {
41
- var i = e && e.prototype instanceof Generator ? e : Generator,
42
- a = Object.create(i.prototype),
43
- c = new Context(n || []);
44
- return o(a, "_invoke", {
45
- value: makeInvokeMethod(t, r, c)
46
- }), a;
47
- }
48
- function tryCatch(t, e, r) {
49
- try {
50
- return {
51
- type: "normal",
52
- arg: t.call(e, r)
53
- };
54
- } catch (t) {
55
- return {
56
- type: "throw",
57
- arg: t
58
- };
59
- }
12
+ var i = n[a](c),
13
+ u = i.value;
14
+ } catch (n) {
15
+ return void e(n);
60
16
  }
61
- e.wrap = wrap;
62
- var h = "suspendedStart",
63
- l = "suspendedYield",
64
- f = "executing",
65
- s = "completed",
66
- y = {};
67
- function Generator() {}
68
- function GeneratorFunction() {}
69
- function GeneratorFunctionPrototype() {}
70
- var p = {};
71
- define(p, a, function () {
72
- return this;
73
- });
74
- var d = Object.getPrototypeOf,
75
- v = d && d(d(values([])));
76
- v && v !== r && n.call(v, a) && (p = v);
77
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
78
- function defineIteratorMethods(t) {
79
- ["next", "throw", "return"].forEach(function (e) {
80
- define(t, e, function (t) {
81
- return this._invoke(e, t);
82
- });
83
- });
84
- }
85
- function AsyncIterator(t, e) {
86
- function invoke(r, o, i, a) {
87
- var c = tryCatch(t[r], t, o);
88
- if ("throw" !== c.type) {
89
- var u = c.arg,
90
- h = u.value;
91
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
92
- invoke("next", t, i, a);
93
- }, function (t) {
94
- invoke("throw", t, i, a);
95
- }) : e.resolve(h).then(function (t) {
96
- u.value = t, i(u);
97
- }, function (t) {
98
- return invoke("throw", t, i, a);
99
- });
17
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
18
+ }
19
+ function _asyncToGenerator(n) {
20
+ return function () {
21
+ var t = this,
22
+ e = arguments;
23
+ return new Promise(function (r, o) {
24
+ var a = n.apply(t, e);
25
+ function _next(n) {
26
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
100
27
  }
101
- a(c.arg);
102
- }
103
- var r;
104
- o(this, "_invoke", {
105
- value: function (t, n) {
106
- function callInvokeWithMethodAndArg() {
107
- return new e(function (e, r) {
108
- invoke(t, n, e, r);
109
- });
110
- }
111
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
28
+ function _throw(n) {
29
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
112
30
  }
31
+ _next(void 0);
113
32
  });
114
- }
115
- function makeInvokeMethod(e, r, n) {
116
- var o = h;
117
- return function (i, a) {
118
- if (o === f) throw new Error("Generator is already running");
119
- if (o === s) {
120
- if ("throw" === i) throw a;
121
- return {
122
- value: t,
123
- done: !0
33
+ };
34
+ }
35
+ function _extends() {
36
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
37
+ for (var e = 1; e < arguments.length; e++) {
38
+ var t = arguments[e];
39
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
40
+ }
41
+ return n;
42
+ }, _extends.apply(null, arguments);
43
+ }
44
+ function _regenerator() {
45
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
46
+ var e,
47
+ t,
48
+ r = "function" == typeof Symbol ? Symbol : {},
49
+ n = r.iterator || "@@iterator",
50
+ o = r.toStringTag || "@@toStringTag";
51
+ function i(r, n, o, i) {
52
+ var c = n && n.prototype instanceof Generator ? n : Generator,
53
+ u = Object.create(c.prototype);
54
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
55
+ var i,
56
+ c,
57
+ u,
58
+ f = 0,
59
+ p = o || [],
60
+ y = !1,
61
+ G = {
62
+ p: 0,
63
+ n: 0,
64
+ v: e,
65
+ a: d,
66
+ f: d.bind(e, 4),
67
+ d: function (t, r) {
68
+ return i = t, c = 0, u = e, G.n = r, a;
69
+ }
124
70
  };
71
+ function d(r, n) {
72
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
73
+ var o,
74
+ i = p[t],
75
+ d = G.p,
76
+ l = i[2];
77
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
78
+ }
79
+ if (o || r > 1) return a;
80
+ throw y = !0, n;
125
81
  }
126
- for (n.method = i, n.arg = a;;) {
127
- var c = n.delegate;
128
- if (c) {
129
- var u = maybeInvokeDelegate(c, n);
130
- if (u) {
131
- if (u === y) continue;
132
- return u;
82
+ return function (o, p, l) {
83
+ if (f > 1) throw TypeError("Generator is already running");
84
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
85
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
86
+ try {
87
+ if (f = 2, i) {
88
+ if (c || (o = "next"), t = i[o]) {
89
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
90
+ if (!t.done) return t;
91
+ u = t.value, c < 2 && (c = 0);
92
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
93
+ i = e;
94
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
95
+ } catch (t) {
96
+ i = e, c = 1, u = t;
97
+ } finally {
98
+ f = 1;
133
99
  }
134
100
  }
135
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
136
- if (o === h) throw o = s, n.arg;
137
- n.dispatchException(n.arg);
138
- } else "return" === n.method && n.abrupt("return", n.arg);
139
- o = f;
140
- var p = tryCatch(e, r, n);
141
- if ("normal" === p.type) {
142
- if (o = n.done ? s : l, p.arg === y) continue;
143
- return {
144
- value: p.arg,
145
- done: n.done
146
- };
147
- }
148
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
149
- }
150
- };
151
- }
152
- function maybeInvokeDelegate(e, r) {
153
- var n = r.method,
154
- o = e.iterator[n];
155
- 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;
156
- var i = tryCatch(o, e.iterator, r.arg);
157
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
158
- var a = i.arg;
159
- 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);
160
- }
161
- function pushTryEntry(t) {
162
- var e = {
163
- tryLoc: t[0]
164
- };
165
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
166
- }
167
- function resetTryEntry(t) {
168
- var e = t.completion || {};
169
- e.type = "normal", delete e.arg, t.completion = e;
170
- }
171
- function Context(t) {
172
- this.tryEntries = [{
173
- tryLoc: "root"
174
- }], t.forEach(pushTryEntry, this), this.reset(!0);
101
+ return {
102
+ value: t,
103
+ done: y
104
+ };
105
+ };
106
+ }(r, o, i), !0), u;
175
107
  }
176
- function values(e) {
177
- if (e || "" === e) {
178
- var r = e[a];
179
- if (r) return r.call(e);
180
- if ("function" == typeof e.next) return e;
181
- if (!isNaN(e.length)) {
182
- var o = -1,
183
- i = function next() {
184
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
185
- return next.value = t, next.done = !0, next;
186
- };
187
- return i.next = i;
188
- }
189
- }
190
- throw new TypeError(typeof e + " is not iterable");
108
+ var a = {};
109
+ function Generator() {}
110
+ function GeneratorFunction() {}
111
+ function GeneratorFunctionPrototype() {}
112
+ t = Object.getPrototypeOf;
113
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
114
+ return this;
115
+ }), t),
116
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
117
+ function f(e) {
118
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
191
119
  }
192
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
193
- value: GeneratorFunctionPrototype,
194
- configurable: !0
195
- }), o(GeneratorFunctionPrototype, "constructor", {
196
- value: GeneratorFunction,
197
- configurable: !0
198
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
199
- var e = "function" == typeof t && t.constructor;
200
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
201
- }, e.mark = function (t) {
202
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
203
- }, e.awrap = function (t) {
204
- return {
205
- __await: t
206
- };
207
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
120
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
208
121
  return this;
209
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
210
- void 0 === i && (i = Promise);
211
- var a = new AsyncIterator(wrap(t, r, n, o), i);
212
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
213
- return t.done ? t.value : a.next();
214
- });
215
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
216
- return this;
217
- }), define(g, "toString", function () {
122
+ }), _regeneratorDefine(u, "toString", function () {
218
123
  return "[object Generator]";
219
- }), e.keys = function (t) {
220
- var e = Object(t),
221
- r = [];
222
- for (var n in e) r.push(n);
223
- return r.reverse(), function next() {
224
- for (; r.length;) {
225
- var t = r.pop();
226
- if (t in e) return next.value = t, next.done = !1, next;
227
- }
228
- return next.done = !0, next;
124
+ }), (_regenerator = function () {
125
+ return {
126
+ w: i,
127
+ m: f
229
128
  };
230
- }, e.values = values, Context.prototype = {
231
- constructor: Context,
232
- reset: function (e) {
233
- 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);
234
- },
235
- stop: function () {
236
- this.done = !0;
237
- var t = this.tryEntries[0].completion;
238
- if ("throw" === t.type) throw t.arg;
239
- return this.rval;
240
- },
241
- dispatchException: function (e) {
242
- if (this.done) throw e;
243
- var r = this;
244
- function handle(n, o) {
245
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
246
- }
247
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
248
- var i = this.tryEntries[o],
249
- a = i.completion;
250
- if ("root" === i.tryLoc) return handle("end");
251
- if (i.tryLoc <= this.prev) {
252
- var c = n.call(i, "catchLoc"),
253
- u = n.call(i, "finallyLoc");
254
- if (c && u) {
255
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
256
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
257
- } else if (c) {
258
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
259
- } else {
260
- if (!u) throw new Error("try statement without catch or finally");
261
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
262
- }
263
- }
264
- }
265
- },
266
- abrupt: function (t, e) {
267
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
268
- var o = this.tryEntries[r];
269
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
270
- var i = o;
271
- break;
272
- }
273
- }
274
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
275
- var a = i ? i.completion : {};
276
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
277
- },
278
- complete: function (t, e) {
279
- if ("throw" === t.type) throw t.arg;
280
- 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;
281
- },
282
- finish: function (t) {
283
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
284
- var r = this.tryEntries[e];
285
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
286
- }
287
- },
288
- catch: function (t) {
289
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
290
- var r = this.tryEntries[e];
291
- if (r.tryLoc === t) {
292
- var n = r.completion;
293
- if ("throw" === n.type) {
294
- var o = n.arg;
295
- resetTryEntry(r);
296
- }
297
- return o;
298
- }
299
- }
300
- throw new Error("illegal catch attempt");
301
- },
302
- delegateYield: function (e, r, n) {
303
- return this.delegate = {
304
- iterator: values(e),
305
- resultName: r,
306
- nextLoc: n
307
- }, "next" === this.method && (this.arg = t), y;
308
- }
309
- }, e;
129
+ })();
310
130
  }
311
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
131
+ function _regeneratorDefine(e, r, n, t) {
132
+ var i = Object.defineProperty;
312
133
  try {
313
- var info = gen[key](arg);
314
- var value = info.value;
315
- } catch (error) {
316
- reject(error);
317
- return;
318
- }
319
- if (info.done) {
320
- resolve(value);
321
- } else {
322
- Promise.resolve(value).then(_next, _throw);
134
+ i({}, "", {});
135
+ } catch (e) {
136
+ i = 0;
323
137
  }
324
- }
325
- function _asyncToGenerator(fn) {
326
- return function () {
327
- var self = this,
328
- args = arguments;
329
- return new Promise(function (resolve, reject) {
330
- var gen = fn.apply(self, args);
331
- function _next(value) {
332
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
333
- }
334
- function _throw(err) {
335
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
336
- }
337
- _next(undefined);
338
- });
339
- };
340
- }
341
- function _extends() {
342
- _extends = Object.assign ? Object.assign.bind() : function (target) {
343
- for (var i = 1; i < arguments.length; i++) {
344
- var source = arguments[i];
345
- for (var key in source) {
346
- if (Object.prototype.hasOwnProperty.call(source, key)) {
347
- target[key] = source[key];
348
- }
349
- }
138
+ _regeneratorDefine = function (e, r, n, t) {
139
+ function o(r, n) {
140
+ _regeneratorDefine(e, r, function (e) {
141
+ return this._invoke(r, n, e);
142
+ });
350
143
  }
351
- return target;
352
- };
353
- return _extends.apply(this, arguments);
144
+ r ? i ? i(e, r, {
145
+ value: n,
146
+ enumerable: !t,
147
+ configurable: !t,
148
+ writable: !t
149
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
150
+ }, _regeneratorDefine(e, r, n, t);
354
151
  }
355
152
 
356
153
  var initialDauthState = {
@@ -464,10 +261,10 @@ function getClientBasePath() {
464
261
  }
465
262
 
466
263
  var getUserAPI = /*#__PURE__*/function () {
467
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(domainName, token) {
264
+ var _ref = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(domainName, token) {
468
265
  var params, response, data;
469
- return _regeneratorRuntime().wrap(function _callee$(_context) {
470
- while (1) switch (_context.prev = _context.next) {
266
+ return _regenerator().w(function (_context) {
267
+ while (1) switch (_context.n) {
471
268
  case 0:
472
269
  params = {
473
270
  method: 'GET',
@@ -476,21 +273,18 @@ var getUserAPI = /*#__PURE__*/function () {
476
273
  'Content-Type': 'application/json'
477
274
  }
478
275
  };
479
- _context.next = 3;
276
+ _context.n = 1;
480
277
  return fetch(getServerBasePath() + "/app/" + domainName + "/user", params);
481
- case 3:
482
- response = _context.sent;
483
- _context.next = 6;
278
+ case 1:
279
+ response = _context.v;
280
+ _context.n = 2;
484
281
  return response.json();
485
- case 6:
486
- data = _context.sent;
487
- return _context.abrupt("return", {
282
+ case 2:
283
+ data = _context.v;
284
+ return _context.a(2, {
488
285
  response: response,
489
286
  data: data
490
287
  });
491
- case 8:
492
- case "end":
493
- return _context.stop();
494
288
  }
495
289
  }, _callee);
496
290
  }));
@@ -499,10 +293,10 @@ var getUserAPI = /*#__PURE__*/function () {
499
293
  };
500
294
  }();
501
295
  var updateUserAPI = /*#__PURE__*/function () {
502
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(domainName, user, token) {
296
+ var _ref2 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(domainName, user, token) {
503
297
  var params, response, data;
504
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
505
- while (1) switch (_context2.prev = _context2.next) {
298
+ return _regenerator().w(function (_context2) {
299
+ while (1) switch (_context2.n) {
506
300
  case 0:
507
301
  params = {
508
302
  method: 'PATCH',
@@ -512,21 +306,18 @@ var updateUserAPI = /*#__PURE__*/function () {
512
306
  },
513
307
  body: JSON.stringify(user)
514
308
  };
515
- _context2.next = 3;
309
+ _context2.n = 1;
516
310
  return fetch(getServerBasePath() + "/app/" + domainName + "/user", params);
517
- case 3:
518
- response = _context2.sent;
519
- _context2.next = 6;
311
+ case 1:
312
+ response = _context2.v;
313
+ _context2.n = 2;
520
314
  return response.json();
521
- case 6:
522
- data = _context2.sent;
523
- return _context2.abrupt("return", {
315
+ case 2:
316
+ data = _context2.v;
317
+ return _context2.a(2, {
524
318
  response: response,
525
319
  data: data
526
320
  });
527
- case 8:
528
- case "end":
529
- return _context2.stop();
530
321
  }
531
322
  }, _callee2);
532
323
  }));
@@ -535,10 +326,10 @@ var updateUserAPI = /*#__PURE__*/function () {
535
326
  };
536
327
  }();
537
328
  var sendEmailVerificationAPI = /*#__PURE__*/function () {
538
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(domainName, token) {
329
+ var _ref3 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(domainName, token) {
539
330
  var params, response, data;
540
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
541
- while (1) switch (_context3.prev = _context3.next) {
331
+ return _regenerator().w(function (_context3) {
332
+ while (1) switch (_context3.n) {
542
333
  case 0:
543
334
  params = {
544
335
  method: 'GET',
@@ -547,21 +338,18 @@ var sendEmailVerificationAPI = /*#__PURE__*/function () {
547
338
  'Content-Type': 'application/json'
548
339
  }
549
340
  };
550
- _context3.next = 3;
341
+ _context3.n = 1;
551
342
  return fetch(getServerBasePath() + "/app/" + domainName + "/resend-email-verification", params);
552
- case 3:
553
- response = _context3.sent;
554
- _context3.next = 6;
343
+ case 1:
344
+ response = _context3.v;
345
+ _context3.n = 2;
555
346
  return response.json();
556
- case 6:
557
- data = _context3.sent;
558
- return _context3.abrupt("return", {
347
+ case 2:
348
+ data = _context3.v;
349
+ return _context3.a(2, {
559
350
  response: response,
560
351
  data: data
561
352
  });
562
- case 8:
563
- case "end":
564
- return _context3.stop();
565
353
  }
566
354
  }, _callee3);
567
355
  }));
@@ -569,111 +357,96 @@ var sendEmailVerificationAPI = /*#__PURE__*/function () {
569
357
  return _ref3.apply(this, arguments);
570
358
  };
571
359
  }();
572
- var refreshAccessTokenAPI = /*#__PURE__*/function () {
573
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(domainName, token) {
360
+ var refreshTokenAPI = /*#__PURE__*/function () {
361
+ var _ref5 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(domainName, refreshToken) {
574
362
  var params, response, data;
575
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
576
- while (1) switch (_context4.prev = _context4.next) {
363
+ return _regenerator().w(function (_context5) {
364
+ while (1) switch (_context5.n) {
577
365
  case 0:
578
366
  params = {
579
- method: 'GET',
367
+ method: 'POST',
580
368
  headers: {
581
- Authorization: token,
582
369
  'Content-Type': 'application/json'
583
- }
370
+ },
371
+ body: JSON.stringify({
372
+ refreshToken: refreshToken
373
+ })
584
374
  };
585
- _context4.next = 3;
586
- return fetch(getServerBasePath() + "/app/" + domainName + "/refresh-access-token", params);
587
- case 3:
588
- response = _context4.sent;
589
- _context4.next = 6;
375
+ _context5.n = 1;
376
+ return fetch(getServerBasePath() + "/app/" + domainName + "/refresh-token", params);
377
+ case 1:
378
+ response = _context5.v;
379
+ _context5.n = 2;
590
380
  return response.json();
591
- case 6:
592
- data = _context4.sent;
593
- return _context4.abrupt("return", {
381
+ case 2:
382
+ data = _context5.v;
383
+ return _context5.a(2, {
594
384
  response: response,
595
385
  data: data
596
386
  });
597
- case 8:
598
- case "end":
599
- return _context4.stop();
600
387
  }
601
- }, _callee4);
388
+ }, _callee5);
602
389
  }));
603
- return function refreshAccessTokenAPI(_x8, _x9) {
604
- return _ref4.apply(this, arguments);
390
+ return function refreshTokenAPI(_x0, _x1) {
391
+ return _ref5.apply(this, arguments);
605
392
  };
606
393
  }();
607
- var verifyTokenAPI = /*#__PURE__*/function () {
608
- var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
609
- var domainName, tsk, token, params, response, data;
610
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
611
- while (1) switch (_context5.prev = _context5.next) {
394
+ var logoutAPI = /*#__PURE__*/function () {
395
+ var _ref6 = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(domainName, refreshToken) {
396
+ var params, response;
397
+ return _regenerator().w(function (_context6) {
398
+ while (1) switch (_context6.n) {
612
399
  case 0:
613
- domainName = _ref5.domainName, tsk = _ref5.tsk, token = _ref5.token;
614
400
  params = {
615
401
  method: 'POST',
616
402
  headers: {
617
- Authorization: token,
618
403
  'Content-Type': 'application/json'
619
404
  },
620
405
  body: JSON.stringify({
621
- tsk: tsk
406
+ refreshToken: refreshToken
622
407
  })
623
408
  };
624
- _context5.next = 4;
625
- return fetch(getServerBasePath() + "/app/" + domainName + "/verify-token", params);
626
- case 4:
627
- response = _context5.sent;
628
- _context5.next = 7;
629
- return response.json();
630
- case 7:
631
- data = _context5.sent;
632
- return _context5.abrupt("return", {
633
- response: response,
634
- data: data
409
+ _context6.n = 1;
410
+ return fetch(getServerBasePath() + "/app/" + domainName + "/logout", params);
411
+ case 1:
412
+ response = _context6.v;
413
+ return _context6.a(2, {
414
+ response: response
635
415
  });
636
- case 9:
637
- case "end":
638
- return _context5.stop();
639
416
  }
640
- }, _callee5);
417
+ }, _callee6);
641
418
  }));
642
- return function verifyTokenAPI(_x10) {
419
+ return function logoutAPI(_x10, _x11) {
643
420
  return _ref6.apply(this, arguments);
644
421
  };
645
422
  }();
646
423
 
647
424
  var TOKEN_LS = 'dauth_state';
648
-
649
- var routes = {
650
- signin: 'signin',
651
- updateUser: 'update-user'
652
- };
425
+ var REFRESH_TOKEN_LS = 'dauth_refresh_token';
653
426
 
654
427
  function setDauthStateAction(_x) {
655
428
  return _setDauthStateAction.apply(this, arguments);
656
429
  }
657
430
  function _setDauthStateAction() {
658
- _setDauthStateAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
659
- var dispatch, token, domainName, getUserFetch;
660
- return _regeneratorRuntime().wrap(function _callee$(_context) {
661
- while (1) switch (_context.prev = _context.next) {
431
+ _setDauthStateAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(_ref) {
432
+ var dispatch, token, refreshToken, domainName, getUserFetch, _t;
433
+ return _regenerator().w(function (_context) {
434
+ while (1) switch (_context.p = _context.n) {
662
435
  case 0:
663
- dispatch = _ref.dispatch, token = _ref.token, domainName = _ref.domainName;
436
+ dispatch = _ref.dispatch, token = _ref.token, refreshToken = _ref.refreshToken, domainName = _ref.domainName;
664
437
  dispatch({
665
438
  type: SET_IS_LOADING,
666
439
  payload: {
667
440
  isLoading: true
668
441
  }
669
442
  });
670
- _context.prev = 2;
671
- _context.next = 5;
443
+ _context.p = 1;
444
+ _context.n = 2;
672
445
  return getUserAPI(domainName, token);
673
- case 5:
674
- getUserFetch = _context.sent;
446
+ case 2:
447
+ getUserFetch = _context.v;
675
448
  if (!(getUserFetch.response.status === 200)) {
676
- _context.next = 12;
449
+ _context.n = 3;
677
450
  break;
678
451
  }
679
452
  dispatch({
@@ -684,32 +457,33 @@ function _setDauthStateAction() {
684
457
  isAuthenticated: true
685
458
  }
686
459
  });
687
- window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);
688
- return _context.abrupt("return", localStorage.setItem(TOKEN_LS, token));
689
- case 12:
690
- return _context.abrupt("return", resetUser(dispatch));
691
- case 13:
692
- _context.next = 19;
460
+ window.history.replaceState({}, document.title, window.location.pathname);
461
+ localStorage.setItem(TOKEN_LS, token);
462
+ localStorage.setItem(REFRESH_TOKEN_LS, refreshToken);
463
+ return _context.a(2);
464
+ case 3:
465
+ return _context.a(2, resetUser(dispatch));
466
+ case 4:
467
+ _context.n = 6;
693
468
  break;
694
- case 15:
695
- _context.prev = 15;
696
- _context.t0 = _context["catch"](2);
697
- console.error(_context.t0);
698
- return _context.abrupt("return", resetUser(dispatch));
699
- case 19:
700
- _context.prev = 19;
469
+ case 5:
470
+ _context.p = 5;
471
+ _t = _context.v;
472
+ console.error(_t);
473
+ return _context.a(2, resetUser(dispatch));
474
+ case 6:
475
+ _context.p = 6;
701
476
  dispatch({
702
477
  type: SET_IS_LOADING,
703
478
  payload: {
704
479
  isLoading: false
705
480
  }
706
481
  });
707
- return _context.finish(19);
708
- case 22:
709
- case "end":
710
- return _context.stop();
482
+ return _context.f(6);
483
+ case 7:
484
+ return _context.a(2);
711
485
  }
712
- }, _callee, null, [[2, 15, 19, 22]]);
486
+ }, _callee, null, [[1, 5, 6, 7]]);
713
487
  }));
714
488
  return _setDauthStateAction.apply(this, arguments);
715
489
  }
@@ -717,34 +491,50 @@ function setAutoLoginAction(_x2) {
717
491
  return _setAutoLoginAction.apply(this, arguments);
718
492
  }
719
493
  function _setAutoLoginAction() {
720
- _setAutoLoginAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
721
- var dispatch, token_ls, domainName, refreshAccessTokenFetch, newToken, getUserFetch;
722
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
723
- while (1) switch (_context2.prev = _context2.next) {
494
+ _setAutoLoginAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(_ref2) {
495
+ var dispatch, domainName, storedRefreshToken, refreshResult, newAccessToken, newRefreshToken, getUserFetch, _t2;
496
+ return _regenerator().w(function (_context2) {
497
+ while (1) switch (_context2.p = _context2.n) {
724
498
  case 0:
725
- dispatch = _ref2.dispatch, token_ls = _ref2.token_ls, domainName = _ref2.domainName;
499
+ dispatch = _ref2.dispatch, domainName = _ref2.domainName;
726
500
  dispatch({
727
501
  type: SET_IS_LOADING,
728
502
  payload: {
729
503
  isLoading: true
730
504
  }
731
505
  });
732
- _context2.prev = 2;
733
- _context2.next = 5;
734
- return refreshAccessTokenAPI(domainName, token_ls);
735
- case 5:
736
- refreshAccessTokenFetch = _context2.sent;
737
- if (!(refreshAccessTokenFetch.response.status === 200)) {
738
- _context2.next = 21;
506
+ storedRefreshToken = localStorage.getItem(REFRESH_TOKEN_LS);
507
+ if (storedRefreshToken) {
508
+ _context2.n = 1;
509
+ break;
510
+ }
511
+ dispatch({
512
+ type: SET_IS_LOADING,
513
+ payload: {
514
+ isLoading: false
515
+ }
516
+ });
517
+ return _context2.a(2, resetUser(dispatch));
518
+ case 1:
519
+ _context2.p = 1;
520
+ _context2.n = 2;
521
+ return refreshTokenAPI(domainName, storedRefreshToken);
522
+ case 2:
523
+ refreshResult = _context2.v;
524
+ if (!(refreshResult.response.status === 200)) {
525
+ _context2.n = 4;
739
526
  break;
740
527
  }
741
- newToken = refreshAccessTokenFetch.data.accessToken || token_ls;
742
- _context2.next = 10;
743
- return getUserAPI(domainName, newToken);
744
- case 10:
745
- getUserFetch = _context2.sent;
528
+ newAccessToken = refreshResult.data.accessToken;
529
+ newRefreshToken = refreshResult.data.refreshToken;
530
+ localStorage.setItem(TOKEN_LS, newAccessToken);
531
+ localStorage.setItem(REFRESH_TOKEN_LS, newRefreshToken);
532
+ _context2.n = 3;
533
+ return getUserAPI(domainName, newAccessToken);
534
+ case 3:
535
+ getUserFetch = _context2.v;
746
536
  if (!(getUserFetch.response.status === 200)) {
747
- _context2.next = 17;
537
+ _context2.n = 4;
748
538
  break;
749
539
  }
750
540
  dispatch({
@@ -755,134 +545,197 @@ function _setAutoLoginAction() {
755
545
  isAuthenticated: true
756
546
  }
757
547
  });
758
- localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
759
- return _context2.abrupt("return");
760
- case 17:
761
- window.location.replace(getClientBasePath() + "/" + domainName + "/" + routes.signin);
762
- return _context2.abrupt("return", resetUser(dispatch));
763
- case 19:
764
- _context2.next = 23;
765
- break;
766
- case 21:
767
- window.location.replace(getClientBasePath() + "/" + domainName + "/" + routes.signin);
768
- return _context2.abrupt("return", resetUser(dispatch));
769
- case 23:
770
- _context2.next = 29;
548
+ return _context2.a(2);
549
+ case 4:
550
+ // Refresh failed — session expired
551
+ resetUser(dispatch);
552
+ _context2.n = 6;
771
553
  break;
772
- case 25:
773
- _context2.prev = 25;
774
- _context2.t0 = _context2["catch"](2);
775
- console.error(_context2.t0);
776
- return _context2.abrupt("return", resetUser(dispatch));
777
- case 29:
778
- _context2.prev = 29;
554
+ case 5:
555
+ _context2.p = 5;
556
+ _t2 = _context2.v;
557
+ console.error(_t2);
558
+ resetUser(dispatch);
559
+ case 6:
560
+ _context2.p = 6;
779
561
  dispatch({
780
562
  type: SET_IS_LOADING,
781
563
  payload: {
782
564
  isLoading: false
783
565
  }
784
566
  });
785
- return _context2.finish(29);
786
- case 32:
787
- case "end":
788
- return _context2.stop();
567
+ return _context2.f(6);
568
+ case 7:
569
+ return _context2.a(2);
789
570
  }
790
- }, _callee2, null, [[2, 25, 29, 32]]);
571
+ }, _callee2, null, [[1, 5, 6, 7]]);
791
572
  }));
792
573
  return _setAutoLoginAction.apply(this, arguments);
793
574
  }
794
- function setLogoutAction(_ref3) {
795
- var dispatch = _ref3.dispatch;
796
- dispatch({
797
- type: SET_IS_LOADING,
798
- payload: {
799
- isLoading: true
800
- }
801
- });
802
- dispatch({
803
- type: LOGIN,
804
- payload: {
805
- user: {
806
- language: window.document.documentElement.getAttribute('lang') || 'es'
807
- },
808
- domain: {},
809
- isAuthenticated: false
810
- }
811
- });
812
- localStorage.removeItem(TOKEN_LS);
813
- return dispatch({
814
- type: SET_IS_LOADING,
815
- payload: {
816
- isLoading: false
817
- }
818
- });
575
+ function setLogoutAction(_x3) {
576
+ return _setLogoutAction.apply(this, arguments);
577
+ }
578
+ function _setLogoutAction() {
579
+ _setLogoutAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(_ref3) {
580
+ var dispatch, domainName, storedRefreshToken;
581
+ return _regenerator().w(function (_context3) {
582
+ while (1) switch (_context3.p = _context3.n) {
583
+ case 0:
584
+ dispatch = _ref3.dispatch, domainName = _ref3.domainName;
585
+ storedRefreshToken = localStorage.getItem(REFRESH_TOKEN_LS);
586
+ if (!(storedRefreshToken && domainName)) {
587
+ _context3.n = 4;
588
+ break;
589
+ }
590
+ _context3.p = 1;
591
+ _context3.n = 2;
592
+ return logoutAPI(domainName, storedRefreshToken);
593
+ case 2:
594
+ _context3.n = 4;
595
+ break;
596
+ case 3:
597
+ _context3.p = 3;
598
+ case 4:
599
+ dispatch({
600
+ type: SET_IS_LOADING,
601
+ payload: {
602
+ isLoading: true
603
+ }
604
+ });
605
+ dispatch({
606
+ type: LOGIN,
607
+ payload: {
608
+ user: {
609
+ language: window.document.documentElement.getAttribute('lang') || 'es'
610
+ },
611
+ domain: {},
612
+ isAuthenticated: false
613
+ }
614
+ });
615
+ localStorage.removeItem(TOKEN_LS);
616
+ localStorage.removeItem(REFRESH_TOKEN_LS);
617
+ return _context3.a(2, dispatch({
618
+ type: SET_IS_LOADING,
619
+ payload: {
620
+ isLoading: false
621
+ }
622
+ }));
623
+ }
624
+ }, _callee3, null, [[1, 3]]);
625
+ }));
626
+ return _setLogoutAction.apply(this, arguments);
627
+ }
628
+ function refreshSessionAction(_x4) {
629
+ return _refreshSessionAction.apply(this, arguments);
819
630
  }
820
- function setUpdateUserAction(_x3) {
631
+ function _refreshSessionAction() {
632
+ _refreshSessionAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(_ref4) {
633
+ var dispatch, domainName, storedRefreshToken, refreshResult, _t4;
634
+ return _regenerator().w(function (_context4) {
635
+ while (1) switch (_context4.p = _context4.n) {
636
+ case 0:
637
+ dispatch = _ref4.dispatch, domainName = _ref4.domainName;
638
+ storedRefreshToken = localStorage.getItem(REFRESH_TOKEN_LS);
639
+ if (storedRefreshToken) {
640
+ _context4.n = 1;
641
+ break;
642
+ }
643
+ return _context4.a(2, resetUser(dispatch));
644
+ case 1:
645
+ _context4.p = 1;
646
+ _context4.n = 2;
647
+ return refreshTokenAPI(domainName, storedRefreshToken);
648
+ case 2:
649
+ refreshResult = _context4.v;
650
+ if (!(refreshResult.response.status === 200)) {
651
+ _context4.n = 3;
652
+ break;
653
+ }
654
+ localStorage.setItem(TOKEN_LS, refreshResult.data.accessToken);
655
+ localStorage.setItem(REFRESH_TOKEN_LS, refreshResult.data.refreshToken);
656
+ return _context4.a(2);
657
+ case 3:
658
+ // Refresh failed — revoked or expired
659
+ resetUser(dispatch);
660
+ _context4.n = 5;
661
+ break;
662
+ case 4:
663
+ _context4.p = 4;
664
+ _t4 = _context4.v;
665
+ console.error(_t4);
666
+ resetUser(dispatch);
667
+ case 5:
668
+ return _context4.a(2);
669
+ }
670
+ }, _callee4, null, [[1, 4]]);
671
+ }));
672
+ return _refreshSessionAction.apply(this, arguments);
673
+ }
674
+ function setUpdateUserAction(_x5) {
821
675
  return _setUpdateUserAction.apply(this, arguments);
822
676
  }
823
677
  function _setUpdateUserAction() {
824
- _setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
825
- var dispatch, domainName, user, token, getUserFetch;
826
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
827
- while (1) switch (_context3.prev = _context3.next) {
678
+ _setUpdateUserAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5(_ref5) {
679
+ var dispatch, domainName, user, token, getUserFetch, _t5;
680
+ return _regenerator().w(function (_context5) {
681
+ while (1) switch (_context5.p = _context5.n) {
828
682
  case 0:
829
- dispatch = _ref4.dispatch, domainName = _ref4.domainName, user = _ref4.user, token = _ref4.token;
683
+ dispatch = _ref5.dispatch, domainName = _ref5.domainName, user = _ref5.user, token = _ref5.token;
830
684
  if (user.language) {
831
685
  window.document.documentElement.setAttribute('lang', user.language);
832
686
  }
833
687
  if (token) {
834
- _context3.next = 5;
688
+ _context5.n = 1;
835
689
  break;
836
690
  }
837
691
  dispatch({
838
692
  type: UPDATE_USER,
839
693
  payload: user
840
694
  });
841
- return _context3.abrupt("return", false);
842
- case 5:
843
- _context3.prev = 5;
844
- _context3.next = 8;
695
+ return _context5.a(2, false);
696
+ case 1:
697
+ _context5.p = 1;
698
+ _context5.n = 2;
845
699
  return updateUserAPI(domainName, user, token);
846
- case 8:
847
- getUserFetch = _context3.sent;
700
+ case 2:
701
+ getUserFetch = _context5.v;
848
702
  if (!(getUserFetch.response.status === 200)) {
849
- _context3.next = 14;
703
+ _context5.n = 3;
850
704
  break;
851
705
  }
852
706
  dispatch({
853
707
  type: UPDATE_USER,
854
708
  payload: getUserFetch.data.user
855
709
  });
856
- return _context3.abrupt("return", true);
857
- case 14:
710
+ return _context5.a(2, true);
711
+ case 3:
858
712
  console.error('Update user error', getUserFetch.data.message);
859
- return _context3.abrupt("return", false);
860
- case 16:
861
- _context3.next = 22;
713
+ return _context5.a(2, false);
714
+ case 4:
715
+ _context5.n = 6;
862
716
  break;
863
- case 18:
864
- _context3.prev = 18;
865
- _context3.t0 = _context3["catch"](5);
866
- console.error('Update user error', _context3.t0);
867
- return _context3.abrupt("return", false);
868
- case 22:
869
- case "end":
870
- return _context3.stop();
717
+ case 5:
718
+ _context5.p = 5;
719
+ _t5 = _context5.v;
720
+ console.error('Update user error', _t5);
721
+ return _context5.a(2, false);
722
+ case 6:
723
+ return _context5.a(2);
871
724
  }
872
- }, _callee3, null, [[5, 18]]);
725
+ }, _callee5, null, [[1, 5]]);
873
726
  }));
874
727
  return _setUpdateUserAction.apply(this, arguments);
875
728
  }
876
- function sendEmailVerificationAction(_x4) {
729
+ function sendEmailVerificationAction(_x6) {
877
730
  return _sendEmailVerificationAction.apply(this, arguments);
878
731
  }
879
732
  function _sendEmailVerificationAction() {
880
- _sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
733
+ _sendEmailVerificationAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref6) {
881
734
  var dispatch, domainName, token, sendEmailFetch;
882
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
883
- while (1) switch (_context4.prev = _context4.next) {
735
+ return _regenerator().w(function (_context6) {
736
+ while (1) switch (_context6.p = _context6.n) {
884
737
  case 0:
885
- dispatch = _ref5.dispatch, domainName = _ref5.domainName, token = _ref5.token;
738
+ dispatch = _ref6.dispatch, domainName = _ref6.domainName, token = _ref6.token;
886
739
  dispatch({
887
740
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
888
741
  payload: true
@@ -894,13 +747,13 @@ function _sendEmailVerificationAction() {
894
747
  message: 'Sending email verification...'
895
748
  }
896
749
  });
897
- _context4.prev = 3;
898
- _context4.next = 6;
750
+ _context6.p = 1;
751
+ _context6.n = 2;
899
752
  return sendEmailVerificationAPI(domainName, token);
900
- case 6:
901
- sendEmailFetch = _context4.sent;
753
+ case 2:
754
+ sendEmailFetch = _context6.v;
902
755
  if (!(sendEmailFetch.response.status === 200)) {
903
- _context4.next = 13;
756
+ _context6.n = 3;
904
757
  break;
905
758
  }
906
759
  dispatch({
@@ -914,8 +767,8 @@ function _sendEmailVerificationAction() {
914
767
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
915
768
  payload: false
916
769
  });
917
- return _context4.abrupt("return", true);
918
- case 13:
770
+ return _context6.a(2, true);
771
+ case 3:
919
772
  dispatch({
920
773
  type: SET_SEND_EMAIL_VERIFICATION_STATUS,
921
774
  payload: {
@@ -927,13 +780,12 @@ function _sendEmailVerificationAction() {
927
780
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
928
781
  payload: false
929
782
  });
930
- return _context4.abrupt("return", false);
931
- case 16:
932
- _context4.next = 23;
783
+ return _context6.a(2, false);
784
+ case 4:
785
+ _context6.n = 6;
933
786
  break;
934
- case 18:
935
- _context4.prev = 18;
936
- _context4.t0 = _context4["catch"](3);
787
+ case 5:
788
+ _context6.p = 5;
937
789
  dispatch({
938
790
  type: SET_SEND_EMAIL_VERIFICATION_STATUS,
939
791
  payload: {
@@ -945,107 +797,68 @@ function _sendEmailVerificationAction() {
945
797
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
946
798
  payload: false
947
799
  });
948
- return _context4.abrupt("return", false);
949
- case 23:
950
- case "end":
951
- return _context4.stop();
800
+ return _context6.a(2, false);
801
+ case 6:
802
+ return _context6.a(2);
952
803
  }
953
- }, _callee4, null, [[3, 18]]);
804
+ }, _callee6, null, [[1, 5]]);
954
805
  }));
955
806
  return _sendEmailVerificationAction.apply(this, arguments);
956
807
  }
957
- function checkTokenAction(_x5) {
958
- return _checkTokenAction.apply(this, arguments);
959
- }
960
- function _checkTokenAction() {
961
- _checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
962
- var dispatch, domainName, token, refreshAccessTokenFetch;
963
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
964
- while (1) switch (_context5.prev = _context5.next) {
965
- case 0:
966
- dispatch = _ref6.dispatch, domainName = _ref6.domainName, token = _ref6.token;
967
- _context5.prev = 1;
968
- _context5.next = 4;
969
- return refreshAccessTokenAPI(domainName, token);
970
- case 4:
971
- refreshAccessTokenFetch = _context5.sent;
972
- if (!(refreshAccessTokenFetch.response.status === 200)) {
973
- _context5.next = 10;
974
- break;
975
- }
976
- if (refreshAccessTokenFetch.data.accessToken) {
977
- localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
978
- }
979
- return _context5.abrupt("return");
980
- case 10:
981
- window.location.replace(getClientBasePath() + "/" + domainName + "/" + routes.signin);
982
- return _context5.abrupt("return", resetUser(dispatch));
983
- case 12:
984
- _context5.next = 18;
985
- break;
986
- case 14:
987
- _context5.prev = 14;
988
- _context5.t0 = _context5["catch"](1);
989
- resetUser(dispatch);
990
- throw _context5.t0;
991
- case 18:
992
- case "end":
993
- return _context5.stop();
994
- }
995
- }, _callee5, null, [[1, 14]]);
996
- }));
997
- return _checkTokenAction.apply(this, arguments);
998
- }
999
- function getAccessTokenAction(_x6) {
808
+ function getAccessTokenAction(_x7) {
1000
809
  return _getAccessTokenAction.apply(this, arguments);
1001
810
  }
1002
811
  ///////////////////////////////////////////
1003
812
  //////////////////////////////////////////
1004
813
  function _getAccessTokenAction() {
1005
- _getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref7) {
1006
- var dispatch, domainName, token_ls, refreshAccessTokenFetch, _refreshAccessTokenFe;
1007
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1008
- while (1) switch (_context6.prev = _context6.next) {
814
+ _getAccessTokenAction = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7(_ref7) {
815
+ var dispatch, domainName, token_ls, payloadB64, payload, expiresIn, refreshedToken;
816
+ return _regenerator().w(function (_context7) {
817
+ while (1) switch (_context7.p = _context7.n) {
1009
818
  case 0:
1010
819
  dispatch = _ref7.dispatch, domainName = _ref7.domainName;
1011
820
  token_ls = localStorage.getItem(TOKEN_LS);
1012
821
  if (token_ls) {
1013
- _context6.next = 4;
822
+ _context7.n = 1;
1014
823
  break;
1015
824
  }
1016
- return _context6.abrupt("return");
1017
- case 4:
1018
- _context6.prev = 4;
1019
- _context6.next = 7;
1020
- return refreshAccessTokenAPI(domainName, token_ls);
1021
- case 7:
1022
- refreshAccessTokenFetch = _context6.sent;
1023
- if (!(refreshAccessTokenFetch.response.status === 200)) {
1024
- _context6.next = 12;
825
+ return _context7.a(2, 'token-not-found');
826
+ case 1:
827
+ _context7.p = 1;
828
+ payloadB64 = token_ls.split('.')[1];
829
+ if (!payloadB64) {
830
+ _context7.n = 3;
1025
831
  break;
1026
832
  }
1027
- return _context6.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
1028
- case 12:
1029
- resetUser(dispatch);
1030
- return _context6.abrupt("return", 'token-not-found');
1031
- case 14:
1032
- _context6.next = 20;
833
+ payload = JSON.parse(atob(payloadB64));
834
+ expiresIn = (payload.exp || 0) * 1000 - Date.now(); // If token expires in less than 5 minutes, refresh proactively
835
+ if (!(expiresIn < 5 * 60 * 1000)) {
836
+ _context7.n = 3;
837
+ break;
838
+ }
839
+ _context7.n = 2;
840
+ return refreshSessionAction({
841
+ dispatch: dispatch,
842
+ domainName: domainName
843
+ });
844
+ case 2:
845
+ refreshedToken = localStorage.getItem(TOKEN_LS);
846
+ return _context7.a(2, refreshedToken || 'token-not-found');
847
+ case 3:
848
+ _context7.n = 5;
1033
849
  break;
1034
- case 16:
1035
- _context6.prev = 16;
1036
- _context6.t0 = _context6["catch"](4);
1037
- resetUser(dispatch);
1038
- throw _context6.t0;
1039
- case 20:
1040
- case "end":
1041
- return _context6.stop();
850
+ case 4:
851
+ _context7.p = 4;
852
+ case 5:
853
+ return _context7.a(2, token_ls);
1042
854
  }
1043
- }, _callee6, null, [[4, 16]]);
855
+ }, _callee7, null, [[1, 4]]);
1044
856
  }));
1045
857
  return _getAccessTokenAction.apply(this, arguments);
1046
858
  }
1047
859
  var resetUser = function resetUser(dispatch) {
1048
860
  localStorage.removeItem(TOKEN_LS);
861
+ localStorage.removeItem(REFRESH_TOKEN_LS);
1049
862
  return dispatch({
1050
863
  type: LOGIN,
1051
864
  payload: {
@@ -1056,216 +869,168 @@ var resetUser = function resetUser(dispatch) {
1056
869
  });
1057
870
  };
1058
871
 
872
+ var routes = {
873
+ signin: 'signin',
874
+ updateUser: 'update-user'
875
+ };
876
+
1059
877
  var DauthProvider = function DauthProvider(props) {
1060
878
  var domainName = props.domainName,
1061
- tsk = props.tsk,
1062
879
  children = props.children;
1063
880
  var _useReducer = React.useReducer(userReducer, initialDauthState),
1064
881
  dauthState = _useReducer[0],
1065
882
  dispatch = _useReducer[1];
1066
- var isValidTsk = React.useCallback( /*#__PURE__*/function () {
1067
- var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(token) {
1068
- var verifyToken;
1069
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1070
- while (1) switch (_context.prev = _context.next) {
1071
- case 0:
1072
- _context.prev = 0;
1073
- _context.next = 3;
1074
- return verifyTokenAPI({
1075
- domainName: domainName,
1076
- token: token,
1077
- tsk: tsk
1078
- });
1079
- case 3:
1080
- verifyToken = _context.sent;
1081
- if (!(verifyToken.response.status !== 200)) {
1082
- _context.next = 6;
1083
- break;
1084
- }
1085
- return _context.abrupt("return", false);
1086
- case 6:
1087
- return _context.abrupt("return", true);
1088
- case 9:
1089
- _context.prev = 9;
1090
- _context.t0 = _context["catch"](0);
1091
- return _context.abrupt("return", false);
1092
- case 12:
1093
- case "end":
1094
- return _context.stop();
1095
- }
1096
- }, _callee, null, [[0, 9]]);
1097
- }));
1098
- return function (_x) {
1099
- return _ref.apply(this, arguments);
1100
- };
1101
- }(), [domainName, tsk]);
1102
- // Check token periodically
1103
- React.useEffect(function () {
1104
- if (!dauthState.isAuthenticated) return;
1105
- var interval = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
1106
- var token_ls, isValid;
1107
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1108
- while (1) switch (_context2.prev = _context2.next) {
1109
- case 0:
1110
- token_ls = localStorage.getItem(TOKEN_LS);
1111
- if (token_ls) {
1112
- _context2.next = 3;
1113
- break;
1114
- }
1115
- return _context2.abrupt("return");
1116
- case 3:
1117
- _context2.next = 5;
1118
- return isValidTsk(token_ls);
1119
- case 5:
1120
- isValid = _context2.sent;
1121
- if (!isValid) {
1122
- _context2.next = 10;
1123
- break;
1124
- }
1125
- return _context2.abrupt("return", checkTokenAction({
1126
- dispatch: dispatch,
1127
- domainName: domainName,
1128
- token: token_ls
1129
- }));
1130
- case 10:
1131
- setLogoutAction({
1132
- dispatch: dispatch
1133
- });
1134
- throw new Error('Ask value in DauthProvider is not valid');
1135
- case 12:
1136
- case "end":
1137
- return _context2.stop();
1138
- }
1139
- }, _callee2);
1140
- })), 1000 * 60 * 5);
1141
- return function () {
1142
- return clearInterval(interval);
1143
- };
1144
- }, [dauthState.isAuthenticated, isValidTsk]);
883
+ var refreshTimerRef = React.useRef(null);
884
+ // Schedule next proactive refresh based on access token expiry
885
+ var scheduleRefresh = React.useCallback(function () {
886
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
887
+ var token = localStorage.getItem(TOKEN_LS);
888
+ if (!token) return;
889
+ try {
890
+ var payloadB64 = token.split('.')[1];
891
+ if (!payloadB64) return;
892
+ var payload = JSON.parse(atob(payloadB64));
893
+ var expiresIn = (payload.exp || 0) * 1000 - Date.now();
894
+ // Refresh 5 minutes before expiry, minimum 10 seconds
895
+ var refreshIn = Math.max(expiresIn - 5 * 60 * 1000, 10000);
896
+ refreshTimerRef.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
897
+ return _regenerator().w(function (_context) {
898
+ while (1) switch (_context.n) {
899
+ case 0:
900
+ _context.n = 1;
901
+ return refreshSessionAction({
902
+ dispatch: dispatch,
903
+ domainName: domainName
904
+ });
905
+ case 1:
906
+ scheduleRefresh();
907
+ case 2:
908
+ return _context.a(2);
909
+ }
910
+ }, _callee);
911
+ })), refreshIn);
912
+ } catch (_) {
913
+ // If decode fails, retry in 5 minutes
914
+ refreshTimerRef.current = setTimeout(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
915
+ return _regenerator().w(function (_context2) {
916
+ while (1) switch (_context2.n) {
917
+ case 0:
918
+ _context2.n = 1;
919
+ return refreshSessionAction({
920
+ dispatch: dispatch,
921
+ domainName: domainName
922
+ });
923
+ case 1:
924
+ scheduleRefresh();
925
+ case 2:
926
+ return _context2.a(2);
927
+ }
928
+ }, _callee2);
929
+ })), 5 * 60 * 1000);
930
+ }
931
+ }, [domainName]);
1145
932
  // Catch login redirect
1146
933
  React.useEffect(function () {
1147
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1148
- var queryString, urlParams, token_url, isValid;
1149
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1150
- while (1) switch (_context3.prev = _context3.next) {
934
+ _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
935
+ var queryString, urlParams, token_url, refresh_url;
936
+ return _regenerator().w(function (_context3) {
937
+ while (1) switch (_context3.n) {
1151
938
  case 0:
1152
939
  queryString = window.location.search;
1153
940
  if (queryString) {
1154
- _context3.next = 3;
941
+ _context3.n = 1;
1155
942
  break;
1156
943
  }
1157
- return _context3.abrupt("return");
1158
- case 3:
944
+ return _context3.a(2);
945
+ case 1:
1159
946
  urlParams = new URLSearchParams(queryString);
1160
947
  token_url = urlParams.get(TOKEN_LS);
1161
- if (!(token_url && !dauthState.isAuthenticated)) {
1162
- _context3.next = 15;
1163
- break;
1164
- }
1165
- _context3.next = 8;
1166
- return isValidTsk(token_url);
1167
- case 8:
1168
- isValid = _context3.sent;
1169
- if (!isValid) {
1170
- _context3.next = 13;
948
+ refresh_url = urlParams.get(REFRESH_TOKEN_LS);
949
+ if (!(token_url && refresh_url && !dauthState.isAuthenticated)) {
950
+ _context3.n = 2;
1171
951
  break;
1172
952
  }
1173
- return _context3.abrupt("return", setDauthStateAction({
953
+ return _context3.a(2, setDauthStateAction({
1174
954
  dispatch: dispatch,
1175
955
  token: token_url,
956
+ refreshToken: refresh_url,
1176
957
  domainName: domainName
1177
958
  }));
1178
- case 13:
1179
- setLogoutAction({
1180
- dispatch: dispatch
1181
- });
1182
- throw new Error('Ask value in DauthProvider is not valid');
1183
- case 15:
1184
- case "end":
1185
- return _context3.stop();
959
+ case 2:
960
+ return _context3.a(2);
1186
961
  }
1187
962
  }, _callee3);
1188
963
  }))();
1189
964
  }, []);
1190
965
  // Auto Login
1191
966
  React.useEffect(function () {
1192
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
1193
- var token_ls, isValid;
1194
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
1195
- while (1) switch (_context4.prev = _context4.next) {
967
+ _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
968
+ var refreshToken;
969
+ return _regenerator().w(function (_context4) {
970
+ while (1) switch (_context4.n) {
1196
971
  case 0:
1197
- token_ls = localStorage.getItem(TOKEN_LS);
1198
- if (!(token_ls && !dauthState.isAuthenticated)) {
1199
- _context4.next = 13;
1200
- break;
1201
- }
1202
- _context4.next = 4;
1203
- return isValidTsk(token_ls);
1204
- case 4:
1205
- isValid = _context4.sent;
1206
- if (!isValid) {
1207
- _context4.next = 9;
972
+ refreshToken = localStorage.getItem(REFRESH_TOKEN_LS);
973
+ if (!(refreshToken && !dauthState.isAuthenticated)) {
974
+ _context4.n = 1;
1208
975
  break;
1209
976
  }
1210
- return _context4.abrupt("return", setAutoLoginAction({
977
+ return _context4.a(2, setAutoLoginAction({
1211
978
  dispatch: dispatch,
1212
- token_ls: token_ls,
1213
979
  domainName: domainName
1214
980
  }));
1215
- case 9:
1216
- setLogoutAction({
1217
- dispatch: dispatch
1218
- });
1219
- throw new Error('Ask value in DauthProvider is not valid');
1220
- case 11:
1221
- _context4.next = 14;
1222
- break;
1223
- case 13:
1224
- return _context4.abrupt("return", dispatch({
981
+ case 1:
982
+ return _context4.a(2, dispatch({
1225
983
  type: SET_IS_LOADING,
1226
984
  payload: {
1227
985
  isLoading: false
1228
986
  }
1229
987
  }));
1230
- case 14:
1231
- case "end":
1232
- return _context4.stop();
988
+ case 2:
989
+ return _context4.a(2);
1233
990
  }
1234
991
  }, _callee4);
1235
992
  }))();
1236
993
  }, []);
994
+ // Schedule proactive refresh when authenticated
995
+ React.useEffect(function () {
996
+ if (dauthState.isAuthenticated) {
997
+ scheduleRefresh();
998
+ }
999
+ return function () {
1000
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
1001
+ };
1002
+ }, [dauthState.isAuthenticated, scheduleRefresh]);
1237
1003
  var loginWithRedirect = React.useCallback(function () {
1238
1004
  return window.location.replace(getClientBasePath() + "/" + domainName + "/" + routes.signin);
1239
1005
  }, [domainName]);
1240
1006
  var logout = React.useCallback(function () {
1007
+ if (refreshTimerRef.current) clearTimeout(refreshTimerRef.current);
1241
1008
  return setLogoutAction({
1242
- dispatch: dispatch
1009
+ dispatch: dispatch,
1010
+ domainName: domainName
1243
1011
  });
1244
- }, []);
1245
- var getAccessToken = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
1012
+ }, [domainName]);
1013
+ var getAccessToken = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
1246
1014
  var token;
1247
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
1248
- while (1) switch (_context5.prev = _context5.next) {
1015
+ return _regenerator().w(function (_context5) {
1016
+ while (1) switch (_context5.n) {
1249
1017
  case 0:
1250
- _context5.next = 2;
1018
+ _context5.n = 1;
1251
1019
  return getAccessTokenAction({
1252
1020
  dispatch: dispatch,
1253
1021
  domainName: domainName
1254
1022
  });
1255
- case 2:
1256
- token = _context5.sent;
1257
- return _context5.abrupt("return", token);
1258
- case 4:
1259
- case "end":
1260
- return _context5.stop();
1023
+ case 1:
1024
+ token = _context5.v;
1025
+ return _context5.a(2, token);
1261
1026
  }
1262
1027
  }, _callee5);
1263
1028
  })), [domainName]);
1264
- var updateUser = React.useCallback( /*#__PURE__*/function () {
1265
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
1029
+ var updateUser = React.useCallback(/*#__PURE__*/function () {
1030
+ var _ref7 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee6(_ref6) {
1266
1031
  var name, lastname, nickname, telPrefix, telSuffix, language, avatar, token_ls, user;
1267
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
1268
- while (1) switch (_context6.prev = _context6.next) {
1032
+ return _regenerator().w(function (_context6) {
1033
+ while (1) switch (_context6.n) {
1269
1034
  case 0:
1270
1035
  name = _ref6.name, lastname = _ref6.lastname, nickname = _ref6.nickname, telPrefix = _ref6.telPrefix, telSuffix = _ref6.telSuffix, language = _ref6.language, avatar = _ref6.avatar;
1271
1036
  token_ls = localStorage.getItem(TOKEN_LS);
@@ -1278,22 +1043,19 @@ var DauthProvider = function DauthProvider(props) {
1278
1043
  language: language,
1279
1044
  avatar: avatar
1280
1045
  };
1281
- _context6.next = 5;
1046
+ _context6.n = 1;
1282
1047
  return setUpdateUserAction({
1283
1048
  dispatch: dispatch,
1284
1049
  domainName: domainName,
1285
1050
  user: user,
1286
1051
  token: token_ls
1287
1052
  });
1288
- case 5:
1289
- return _context6.abrupt("return", _context6.sent);
1290
- case 6:
1291
- case "end":
1292
- return _context6.stop();
1053
+ case 1:
1054
+ return _context6.a(2, _context6.v);
1293
1055
  }
1294
1056
  }, _callee6);
1295
1057
  }));
1296
- return function (_x2) {
1058
+ return function (_x) {
1297
1059
  return _ref7.apply(this, arguments);
1298
1060
  };
1299
1061
  }(), [domainName]);
@@ -1302,29 +1064,26 @@ var DauthProvider = function DauthProvider(props) {
1302
1064
  if (!token_ls) return;
1303
1065
  return window.location.replace(getClientBasePath() + "/" + domainName + "/" + routes.updateUser + "/" + token_ls);
1304
1066
  }, [domainName]);
1305
- var sendEmailVerification = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
1067
+ var sendEmailVerification = React.useCallback(/*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee7() {
1306
1068
  var token_ls;
1307
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
1308
- while (1) switch (_context7.prev = _context7.next) {
1069
+ return _regenerator().w(function (_context7) {
1070
+ while (1) switch (_context7.n) {
1309
1071
  case 0:
1310
1072
  token_ls = localStorage.getItem(TOKEN_LS);
1311
1073
  if (token_ls) {
1312
- _context7.next = 3;
1074
+ _context7.n = 1;
1313
1075
  break;
1314
1076
  }
1315
- return _context7.abrupt("return", false);
1316
- case 3:
1317
- _context7.next = 5;
1077
+ return _context7.a(2, false);
1078
+ case 1:
1079
+ _context7.n = 2;
1318
1080
  return sendEmailVerificationAction({
1319
1081
  dispatch: dispatch,
1320
1082
  domainName: domainName,
1321
1083
  token: token_ls
1322
1084
  });
1323
- case 5:
1324
- return _context7.abrupt("return", _context7.sent);
1325
- case 6:
1326
- case "end":
1327
- return _context7.stop();
1085
+ case 2:
1086
+ return _context7.a(2, _context7.v);
1328
1087
  }
1329
1088
  }, _callee7);
1330
1089
  })), [domainName]);