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