@plasmicapp/auth-react 0.0.6 → 0.0.8

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.
@@ -5,695 +5,339 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var authApi = require('@plasmicapp/auth-api');
6
6
  var query = require('@plasmicapp/query');
7
7
 
8
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
8
+ function _regeneratorRuntime() {
9
+ _regeneratorRuntime = function () {
10
+ return e;
11
+ };
12
+ var t,
13
+ e = {},
14
+ r = Object.prototype,
15
+ n = r.hasOwnProperty,
16
+ o = Object.defineProperty || function (t, e, r) {
17
+ t[e] = r.value;
18
+ },
19
+ i = "function" == typeof Symbol ? Symbol : {},
20
+ a = i.iterator || "@@iterator",
21
+ c = i.asyncIterator || "@@asyncIterator",
22
+ u = i.toStringTag || "@@toStringTag";
23
+ function define(t, e, r) {
24
+ return Object.defineProperty(t, e, {
25
+ value: r,
26
+ enumerable: !0,
27
+ configurable: !0,
28
+ writable: !0
29
+ }), t[e];
30
+ }
9
31
  try {
10
- var info = gen[key](arg);
11
- var value = info.value;
12
- } catch (error) {
13
- reject(error);
14
- return;
32
+ define({}, "");
33
+ } catch (t) {
34
+ define = function (t, e, r) {
35
+ return t[e] = r;
36
+ };
15
37
  }
16
- if (info.done) {
17
- resolve(value);
18
- } else {
19
- Promise.resolve(value).then(_next, _throw);
38
+ function wrap(t, e, r, n) {
39
+ var i = e && e.prototype instanceof Generator ? e : Generator,
40
+ a = Object.create(i.prototype),
41
+ c = new Context(n || []);
42
+ return o(a, "_invoke", {
43
+ value: makeInvokeMethod(t, r, c)
44
+ }), a;
20
45
  }
21
- }
22
- function _asyncToGenerator(fn) {
23
- return function () {
24
- var self = this,
25
- args = arguments;
26
- return new Promise(function (resolve, reject) {
27
- var gen = fn.apply(self, args);
28
- function _next(value) {
29
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
30
- }
31
- function _throw(err) {
32
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
33
- }
34
- _next(undefined);
35
- });
36
- };
37
- }
38
-
39
- function createCommonjsModule(fn, module) {
40
- return module = { exports: {} }, fn(module, module.exports), module.exports;
41
- }
42
-
43
- var runtime_1 = /*#__PURE__*/createCommonjsModule(function (module) {
44
- /**
45
- * Copyright (c) 2014-present, Facebook, Inc.
46
- *
47
- * This source code is licensed under the MIT license found in the
48
- * LICENSE file in the root directory of this source tree.
49
- */
50
-
51
- var runtime = function (exports) {
52
-
53
- var Op = Object.prototype;
54
- var hasOwn = Op.hasOwnProperty;
55
- var undefined$1; // More compressible than void 0.
56
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
57
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
58
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
59
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
60
- function define(obj, key, value) {
61
- Object.defineProperty(obj, key, {
62
- value: value,
63
- enumerable: true,
64
- configurable: true,
65
- writable: true
66
- });
67
- return obj[key];
68
- }
46
+ function tryCatch(t, e, r) {
69
47
  try {
70
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
71
- define({}, "");
72
- } catch (err) {
73
- define = function define(obj, key, value) {
74
- return obj[key] = value;
48
+ return {
49
+ type: "normal",
50
+ arg: t.call(e, r)
51
+ };
52
+ } catch (t) {
53
+ return {
54
+ type: "throw",
55
+ arg: t
75
56
  };
76
57
  }
77
- function wrap(innerFn, outerFn, self, tryLocsList) {
78
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
79
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
80
- var generator = Object.create(protoGenerator.prototype);
81
- var context = new Context(tryLocsList || []);
82
-
83
- // The ._invoke method unifies the implementations of the .next,
84
- // .throw, and .return methods.
85
- generator._invoke = makeInvokeMethod(innerFn, self, context);
86
- return generator;
87
- }
88
- exports.wrap = wrap;
89
-
90
- // Try/catch helper to minimize deoptimizations. Returns a completion
91
- // record like context.tryEntries[i].completion. This interface could
92
- // have been (and was previously) designed to take a closure to be
93
- // invoked without arguments, but in all the cases we care about we
94
- // already have an existing method we want to call, so there's no need
95
- // to create a new function object. We can even get away with assuming
96
- // the method takes exactly one argument, since that happens to be true
97
- // in every case, so we don't have to touch the arguments object. The
98
- // only additional allocation required is the completion record, which
99
- // has a stable shape and so hopefully should be cheap to allocate.
100
- function tryCatch(fn, obj, arg) {
101
- try {
102
- return {
103
- type: "normal",
104
- arg: fn.call(obj, arg)
105
- };
106
- } catch (err) {
107
- return {
108
- type: "throw",
109
- arg: err
110
- };
111
- }
112
- }
113
- var GenStateSuspendedStart = "suspendedStart";
114
- var GenStateSuspendedYield = "suspendedYield";
115
- var GenStateExecuting = "executing";
116
- var GenStateCompleted = "completed";
117
-
118
- // Returning this object from the innerFn has the same effect as
119
- // breaking out of the dispatch switch statement.
120
- var ContinueSentinel = {};
121
-
122
- // Dummy constructor functions that we use as the .constructor and
123
- // .constructor.prototype properties for functions that return Generator
124
- // objects. For full spec compliance, you may wish to configure your
125
- // minifier not to mangle the names of these two functions.
126
- function Generator() {}
127
- function GeneratorFunction() {}
128
- function GeneratorFunctionPrototype() {}
129
-
130
- // This is a polyfill for %IteratorPrototype% for environments that
131
- // don't natively support it.
132
- var IteratorPrototype = {};
133
- define(IteratorPrototype, iteratorSymbol, function () {
134
- return this;
58
+ }
59
+ e.wrap = wrap;
60
+ var h = "suspendedStart",
61
+ l = "suspendedYield",
62
+ f = "executing",
63
+ s = "completed",
64
+ y = {};
65
+ function Generator() {}
66
+ function GeneratorFunction() {}
67
+ function GeneratorFunctionPrototype() {}
68
+ var p = {};
69
+ define(p, a, function () {
70
+ return this;
71
+ });
72
+ var d = Object.getPrototypeOf,
73
+ v = d && d(d(values([])));
74
+ v && v !== r && n.call(v, a) && (p = v);
75
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
76
+ function defineIteratorMethods(t) {
77
+ ["next", "throw", "return"].forEach(function (e) {
78
+ define(t, e, function (t) {
79
+ return this._invoke(e, t);
80
+ });
135
81
  });
136
- var getProto = Object.getPrototypeOf;
137
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
138
- if (NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
139
- // This environment has a native %IteratorPrototype%; use it instead
140
- // of the polyfill.
141
- IteratorPrototype = NativeIteratorPrototype;
142
- }
143
- var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
144
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
145
- define(Gp, "constructor", GeneratorFunctionPrototype);
146
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
147
- GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction");
148
-
149
- // Helper for defining the .next, .throw, and .return methods of the
150
- // Iterator interface in terms of a single ._invoke method.
151
- function defineIteratorMethods(prototype) {
152
- ["next", "throw", "return"].forEach(function (method) {
153
- define(prototype, method, function (arg) {
154
- return this._invoke(method, arg);
82
+ }
83
+ function AsyncIterator(t, e) {
84
+ function invoke(r, o, i, a) {
85
+ var c = tryCatch(t[r], t, o);
86
+ if ("throw" !== c.type) {
87
+ var u = c.arg,
88
+ h = u.value;
89
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
90
+ invoke("next", t, i, a);
91
+ }, function (t) {
92
+ invoke("throw", t, i, a);
93
+ }) : e.resolve(h).then(function (t) {
94
+ u.value = t, i(u);
95
+ }, function (t) {
96
+ return invoke("throw", t, i, a);
155
97
  });
156
- });
157
- }
158
- exports.isGeneratorFunction = function (genFun) {
159
- var ctor = typeof genFun === "function" && genFun.constructor;
160
- return ctor ? ctor === GeneratorFunction ||
161
- // For the native GeneratorFunction constructor, the best we can
162
- // do is to check its .name property.
163
- (ctor.displayName || ctor.name) === "GeneratorFunction" : false;
164
- };
165
- exports.mark = function (genFun) {
166
- if (Object.setPrototypeOf) {
167
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
168
- } else {
169
- genFun.__proto__ = GeneratorFunctionPrototype;
170
- define(genFun, toStringTagSymbol, "GeneratorFunction");
171
- }
172
- genFun.prototype = Object.create(Gp);
173
- return genFun;
174
- };
175
-
176
- // Within the body of any async function, `await x` is transformed to
177
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
178
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
179
- // meant to be awaited.
180
- exports.awrap = function (arg) {
181
- return {
182
- __await: arg
183
- };
184
- };
185
- function AsyncIterator(generator, PromiseImpl) {
186
- function invoke(method, arg, resolve, reject) {
187
- var record = tryCatch(generator[method], generator, arg);
188
- if (record.type === "throw") {
189
- reject(record.arg);
190
- } else {
191
- var result = record.arg;
192
- var value = result.value;
193
- if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
194
- return PromiseImpl.resolve(value.__await).then(function (value) {
195
- invoke("next", value, resolve, reject);
196
- }, function (err) {
197
- invoke("throw", err, resolve, reject);
198
- });
199
- }
200
- return PromiseImpl.resolve(value).then(function (unwrapped) {
201
- // When a yielded Promise is resolved, its final value becomes
202
- // the .value of the Promise<{value,done}> result for the
203
- // current iteration.
204
- result.value = unwrapped;
205
- resolve(result);
206
- }, function (error) {
207
- // If a rejected Promise was yielded, throw the rejection back
208
- // into the async generator function so it can be handled there.
209
- return invoke("throw", error, resolve, reject);
210
- });
211
- }
212
98
  }
213
- var previousPromise;
214
- function enqueue(method, arg) {
99
+ a(c.arg);
100
+ }
101
+ var r;
102
+ o(this, "_invoke", {
103
+ value: function (t, n) {
215
104
  function callInvokeWithMethodAndArg() {
216
- return new PromiseImpl(function (resolve, reject) {
217
- invoke(method, arg, resolve, reject);
105
+ return new e(function (e, r) {
106
+ invoke(t, n, e, r);
218
107
  });
219
108
  }
220
- return previousPromise =
221
- // If enqueue has been called before, then we want to wait until
222
- // all previous Promises have been resolved before calling invoke,
223
- // so that results are always delivered in the correct order. If
224
- // enqueue has not been called before, then it is important to
225
- // call invoke immediately, without waiting on a callback to fire,
226
- // so that the async generator function has the opportunity to do
227
- // any necessary setup in a predictable way. This predictability
228
- // is why the Promise constructor synchronously invokes its
229
- // executor callback, and why async functions synchronously
230
- // execute code before the first await. Since we implement simple
231
- // async functions in terms of async generators, it is especially
232
- // important to get this right, even though it requires care.
233
- previousPromise ? previousPromise.then(callInvokeWithMethodAndArg,
234
- // Avoid propagating failures to Promises returned by later
235
- // invocations of the iterator.
236
- callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
109
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
237
110
  }
238
-
239
- // Define the unified helper method that is used to implement .next,
240
- // .throw, and .return (see defineIteratorMethods).
241
- this._invoke = enqueue;
242
- }
243
- defineIteratorMethods(AsyncIterator.prototype);
244
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
245
- return this;
246
111
  });
247
- exports.AsyncIterator = AsyncIterator;
248
-
249
- // Note that simple async functions are implemented on top of
250
- // AsyncIterator objects; they just return a Promise for the value of
251
- // the final result produced by the iterator.
252
- exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) {
253
- if (PromiseImpl === void 0) PromiseImpl = Promise;
254
- var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl);
255
- return exports.isGeneratorFunction(outerFn) ? iter // If outerFn is a generator, return the full iterator.
256
- : iter.next().then(function (result) {
257
- return result.done ? result.value : iter.next();
258
- });
259
- };
260
- function makeInvokeMethod(innerFn, self, context) {
261
- var state = GenStateSuspendedStart;
262
- return function invoke(method, arg) {
263
- if (state === GenStateExecuting) {
264
- throw new Error("Generator is already running");
265
- }
266
- if (state === GenStateCompleted) {
267
- if (method === "throw") {
268
- throw arg;
269
- }
270
-
271
- // Be forgiving, per 25.3.3.3.3 of the spec:
272
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
273
- return doneResult();
274
- }
275
- context.method = method;
276
- context.arg = arg;
277
- while (true) {
278
- var delegate = context.delegate;
279
- if (delegate) {
280
- var delegateResult = maybeInvokeDelegate(delegate, context);
281
- if (delegateResult) {
282
- if (delegateResult === ContinueSentinel) continue;
283
- return delegateResult;
284
- }
285
- }
286
- if (context.method === "next") {
287
- // Setting context._sent for legacy support of Babel's
288
- // function.sent implementation.
289
- context.sent = context._sent = context.arg;
290
- } else if (context.method === "throw") {
291
- if (state === GenStateSuspendedStart) {
292
- state = GenStateCompleted;
293
- throw context.arg;
294
- }
295
- context.dispatchException(context.arg);
296
- } else if (context.method === "return") {
297
- context.abrupt("return", context.arg);
298
- }
299
- state = GenStateExecuting;
300
- var record = tryCatch(innerFn, self, context);
301
- if (record.type === "normal") {
302
- // If an exception is thrown from innerFn, we leave state ===
303
- // GenStateExecuting and loop back for another invocation.
304
- state = context.done ? GenStateCompleted : GenStateSuspendedYield;
305
- if (record.arg === ContinueSentinel) {
306
- continue;
307
- }
308
- return {
309
- value: record.arg,
310
- done: context.done
311
- };
312
- } else if (record.type === "throw") {
313
- state = GenStateCompleted;
314
- // Dispatch the exception by looping back around to the
315
- // context.dispatchException(context.arg) call above.
316
- context.method = "throw";
317
- context.arg = record.arg;
112
+ }
113
+ function makeInvokeMethod(e, r, n) {
114
+ var o = h;
115
+ return function (i, a) {
116
+ if (o === f) throw new Error("Generator is already running");
117
+ if (o === s) {
118
+ if ("throw" === i) throw a;
119
+ return {
120
+ value: t,
121
+ done: !0
122
+ };
123
+ }
124
+ for (n.method = i, n.arg = a;;) {
125
+ var c = n.delegate;
126
+ if (c) {
127
+ var u = maybeInvokeDelegate(c, n);
128
+ if (u) {
129
+ if (u === y) continue;
130
+ return u;
318
131
  }
319
132
  }
320
- };
321
- }
322
-
323
- // Call delegate.iterator[context.method](context.arg) and handle the
324
- // result, either by returning a { value, done } result from the
325
- // delegate iterator, or by modifying context.method and context.arg,
326
- // setting context.delegate to null, and returning the ContinueSentinel.
327
- function maybeInvokeDelegate(delegate, context) {
328
- var method = delegate.iterator[context.method];
329
- if (method === undefined$1) {
330
- // A .throw or .return when the delegate iterator has no .throw
331
- // method always terminates the yield* loop.
332
- context.delegate = null;
333
- if (context.method === "throw") {
334
- // Note: ["return"] must be used for ES3 parsing compatibility.
335
- if (delegate.iterator["return"]) {
336
- // If the delegate iterator has a return method, give it a
337
- // chance to clean up.
338
- context.method = "return";
339
- context.arg = undefined$1;
340
- maybeInvokeDelegate(delegate, context);
341
- if (context.method === "throw") {
342
- // If maybeInvokeDelegate(context) changed context.method from
343
- // "return" to "throw", let that override the TypeError below.
344
- return ContinueSentinel;
345
- }
346
- }
347
- context.method = "throw";
348
- context.arg = new TypeError("The iterator does not provide a 'throw' method");
133
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
134
+ if (o === h) throw o = s, n.arg;
135
+ n.dispatchException(n.arg);
136
+ } else "return" === n.method && n.abrupt("return", n.arg);
137
+ o = f;
138
+ var p = tryCatch(e, r, n);
139
+ if ("normal" === p.type) {
140
+ if (o = n.done ? s : l, p.arg === y) continue;
141
+ return {
142
+ value: p.arg,
143
+ done: n.done
144
+ };
349
145
  }
350
- return ContinueSentinel;
351
- }
352
- var record = tryCatch(method, delegate.iterator, context.arg);
353
- if (record.type === "throw") {
354
- context.method = "throw";
355
- context.arg = record.arg;
356
- context.delegate = null;
357
- return ContinueSentinel;
146
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
358
147
  }
359
- var info = record.arg;
360
- if (!info) {
361
- context.method = "throw";
362
- context.arg = new TypeError("iterator result is not an object");
363
- context.delegate = null;
364
- return ContinueSentinel;
365
- }
366
- if (info.done) {
367
- // Assign the result of the finished delegate to the temporary
368
- // variable specified by delegate.resultName (see delegateYield).
369
- context[delegate.resultName] = info.value;
370
-
371
- // Resume execution at the desired location (see delegateYield).
372
- context.next = delegate.nextLoc;
373
-
374
- // If context.method was "throw" but the delegate handled the
375
- // exception, let the outer generator proceed normally. If
376
- // context.method was "next", forget context.arg since it has been
377
- // "consumed" by the delegate iterator. If context.method was
378
- // "return", allow the original .return call to continue in the
379
- // outer generator.
380
- if (context.method !== "return") {
381
- context.method = "next";
382
- context.arg = undefined$1;
383
- }
384
- } else {
385
- // Re-yield the result returned by the delegate method.
386
- return info;
148
+ };
149
+ }
150
+ function maybeInvokeDelegate(e, r) {
151
+ var n = r.method,
152
+ o = e.iterator[n];
153
+ 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;
154
+ var i = tryCatch(o, e.iterator, r.arg);
155
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
156
+ var a = i.arg;
157
+ 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);
158
+ }
159
+ function pushTryEntry(t) {
160
+ var e = {
161
+ tryLoc: t[0]
162
+ };
163
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
164
+ }
165
+ function resetTryEntry(t) {
166
+ var e = t.completion || {};
167
+ e.type = "normal", delete e.arg, t.completion = e;
168
+ }
169
+ function Context(t) {
170
+ this.tryEntries = [{
171
+ tryLoc: "root"
172
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
173
+ }
174
+ function values(e) {
175
+ if (e || "" === e) {
176
+ var r = e[a];
177
+ if (r) return r.call(e);
178
+ if ("function" == typeof e.next) return e;
179
+ if (!isNaN(e.length)) {
180
+ var o = -1,
181
+ i = function next() {
182
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
183
+ return next.value = t, next.done = !0, next;
184
+ };
185
+ return i.next = i;
387
186
  }
388
-
389
- // The delegate iterator is finished, so forget it and continue with
390
- // the outer generator.
391
- context.delegate = null;
392
- return ContinueSentinel;
393
187
  }
394
-
395
- // Define Generator.prototype.{next,throw,return} in terms of the
396
- // unified ._invoke helper method.
397
- defineIteratorMethods(Gp);
398
- define(Gp, toStringTagSymbol, "Generator");
399
-
400
- // A Generator should always return itself as the iterator object when the
401
- // @@iterator function is called on it. Some browsers' implementations of the
402
- // iterator prototype chain incorrectly implement this, causing the Generator
403
- // object to not be returned from this call. This ensures that doesn't happen.
404
- // See https://github.com/facebook/regenerator/issues/274 for more details.
405
- define(Gp, iteratorSymbol, function () {
406
- return this;
407
- });
408
- define(Gp, "toString", function () {
409
- return "[object Generator]";
188
+ throw new TypeError(typeof e + " is not iterable");
189
+ }
190
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
191
+ value: GeneratorFunctionPrototype,
192
+ configurable: !0
193
+ }), o(GeneratorFunctionPrototype, "constructor", {
194
+ value: GeneratorFunction,
195
+ configurable: !0
196
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
197
+ var e = "function" == typeof t && t.constructor;
198
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
199
+ }, e.mark = function (t) {
200
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
201
+ }, e.awrap = function (t) {
202
+ return {
203
+ __await: t
204
+ };
205
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
206
+ return this;
207
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
208
+ void 0 === i && (i = Promise);
209
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
210
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
211
+ return t.done ? t.value : a.next();
410
212
  });
411
- function pushTryEntry(locs) {
412
- var entry = {
413
- tryLoc: locs[0]
414
- };
415
- if (1 in locs) {
416
- entry.catchLoc = locs[1];
213
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
214
+ return this;
215
+ }), define(g, "toString", function () {
216
+ return "[object Generator]";
217
+ }), e.keys = function (t) {
218
+ var e = Object(t),
219
+ r = [];
220
+ for (var n in e) r.push(n);
221
+ return r.reverse(), function next() {
222
+ for (; r.length;) {
223
+ var t = r.pop();
224
+ if (t in e) return next.value = t, next.done = !1, next;
417
225
  }
418
- if (2 in locs) {
419
- entry.finallyLoc = locs[2];
420
- entry.afterLoc = locs[3];
421
- }
422
- this.tryEntries.push(entry);
423
- }
424
- function resetTryEntry(entry) {
425
- var record = entry.completion || {};
426
- record.type = "normal";
427
- delete record.arg;
428
- entry.completion = record;
429
- }
430
- function Context(tryLocsList) {
431
- // The root entry object (effectively a try statement without a catch
432
- // or a finally block) gives us a place to store values thrown from
433
- // locations where there is no enclosing try statement.
434
- this.tryEntries = [{
435
- tryLoc: "root"
436
- }];
437
- tryLocsList.forEach(pushTryEntry, this);
438
- this.reset(true);
439
- }
440
- exports.keys = function (object) {
441
- var keys = [];
442
- for (var key in object) {
443
- keys.push(key);
444
- }
445
- keys.reverse();
446
-
447
- // Rather than returning an object with a next method, we keep
448
- // things simple and return the next function itself.
449
- return function next() {
450
- while (keys.length) {
451
- var key = keys.pop();
452
- if (key in object) {
453
- next.value = key;
454
- next.done = false;
455
- return next;
456
- }
457
- }
458
-
459
- // To avoid creating an additional object, we just hang the .value
460
- // and .done properties off the next function object itself. This
461
- // also ensures that the minifier will not anonymize the function.
462
- next.done = true;
463
- return next;
464
- };
226
+ return next.done = !0, next;
465
227
  };
466
- function values(iterable) {
467
- if (iterable) {
468
- var iteratorMethod = iterable[iteratorSymbol];
469
- if (iteratorMethod) {
470
- return iteratorMethod.call(iterable);
471
- }
472
- if (typeof iterable.next === "function") {
473
- return iterable;
474
- }
475
- if (!isNaN(iterable.length)) {
476
- var i = -1,
477
- next = function next() {
478
- while (++i < iterable.length) {
479
- if (hasOwn.call(iterable, i)) {
480
- next.value = iterable[i];
481
- next.done = false;
482
- return next;
483
- }
484
- }
485
- next.value = undefined$1;
486
- next.done = true;
487
- return next;
488
- };
489
- return next.next = next;
490
- }
228
+ }, e.values = values, Context.prototype = {
229
+ constructor: Context,
230
+ reset: function (e) {
231
+ 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);
232
+ },
233
+ stop: function () {
234
+ this.done = !0;
235
+ var t = this.tryEntries[0].completion;
236
+ if ("throw" === t.type) throw t.arg;
237
+ return this.rval;
238
+ },
239
+ dispatchException: function (e) {
240
+ if (this.done) throw e;
241
+ var r = this;
242
+ function handle(n, o) {
243
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
491
244
  }
492
-
493
- // Return an iterator with no values.
494
- return {
495
- next: doneResult
496
- };
497
- }
498
- exports.values = values;
499
- function doneResult() {
500
- return {
501
- value: undefined$1,
502
- done: true
503
- };
504
- }
505
- Context.prototype = {
506
- constructor: Context,
507
- reset: function reset(skipTempReset) {
508
- this.prev = 0;
509
- this.next = 0;
510
- // Resetting context._sent for legacy support of Babel's
511
- // function.sent implementation.
512
- this.sent = this._sent = undefined$1;
513
- this.done = false;
514
- this.delegate = null;
515
- this.method = "next";
516
- this.arg = undefined$1;
517
- this.tryEntries.forEach(resetTryEntry);
518
- if (!skipTempReset) {
519
- for (var name in this) {
520
- // Not sure about the optimal order of these conditions:
521
- if (name.charAt(0) === "t" && hasOwn.call(this, name) && !isNaN(+name.slice(1))) {
522
- this[name] = undefined$1;
523
- }
524
- }
525
- }
526
- },
527
- stop: function stop() {
528
- this.done = true;
529
- var rootEntry = this.tryEntries[0];
530
- var rootRecord = rootEntry.completion;
531
- if (rootRecord.type === "throw") {
532
- throw rootRecord.arg;
533
- }
534
- return this.rval;
535
- },
536
- dispatchException: function dispatchException(exception) {
537
- if (this.done) {
538
- throw exception;
539
- }
540
- var context = this;
541
- function handle(loc, caught) {
542
- record.type = "throw";
543
- record.arg = exception;
544
- context.next = loc;
545
- if (caught) {
546
- // If the dispatched exception was caught by a catch block,
547
- // then let that catch block handle the exception normally.
548
- context.method = "next";
549
- context.arg = undefined$1;
245
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
246
+ var i = this.tryEntries[o],
247
+ a = i.completion;
248
+ if ("root" === i.tryLoc) return handle("end");
249
+ if (i.tryLoc <= this.prev) {
250
+ var c = n.call(i, "catchLoc"),
251
+ u = n.call(i, "finallyLoc");
252
+ if (c && u) {
253
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
254
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
255
+ } else if (c) {
256
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
257
+ } else {
258
+ if (!u) throw new Error("try statement without catch or finally");
259
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
550
260
  }
551
- return !!caught;
552
- }
553
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
554
- var entry = this.tryEntries[i];
555
- var record = entry.completion;
556
- if (entry.tryLoc === "root") {
557
- // Exception thrown outside of any try block that could handle
558
- // it, so set the completion value of the entire function to
559
- // throw the exception.
560
- return handle("end");
561
- }
562
- if (entry.tryLoc <= this.prev) {
563
- var hasCatch = hasOwn.call(entry, "catchLoc");
564
- var hasFinally = hasOwn.call(entry, "finallyLoc");
565
- if (hasCatch && hasFinally) {
566
- if (this.prev < entry.catchLoc) {
567
- return handle(entry.catchLoc, true);
568
- } else if (this.prev < entry.finallyLoc) {
569
- return handle(entry.finallyLoc);
570
- }
571
- } else if (hasCatch) {
572
- if (this.prev < entry.catchLoc) {
573
- return handle(entry.catchLoc, true);
574
- }
575
- } else if (hasFinally) {
576
- if (this.prev < entry.finallyLoc) {
577
- return handle(entry.finallyLoc);
578
- }
579
- } else {
580
- throw new Error("try statement without catch or finally");
581
- }
582
- }
583
- }
584
- },
585
- abrupt: function abrupt(type, arg) {
586
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
587
- var entry = this.tryEntries[i];
588
- if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) {
589
- var finallyEntry = entry;
590
- break;
591
- }
592
- }
593
- if (finallyEntry && (type === "break" || type === "continue") && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc) {
594
- // Ignore the finally entry if control is not jumping to a
595
- // location outside the try/catch block.
596
- finallyEntry = null;
597
261
  }
598
- var record = finallyEntry ? finallyEntry.completion : {};
599
- record.type = type;
600
- record.arg = arg;
601
- if (finallyEntry) {
602
- this.method = "next";
603
- this.next = finallyEntry.finallyLoc;
604
- return ContinueSentinel;
605
- }
606
- return this.complete(record);
607
- },
608
- complete: function complete(record, afterLoc) {
609
- if (record.type === "throw") {
610
- throw record.arg;
611
- }
612
- if (record.type === "break" || record.type === "continue") {
613
- this.next = record.arg;
614
- } else if (record.type === "return") {
615
- this.rval = this.arg = record.arg;
616
- this.method = "return";
617
- this.next = "end";
618
- } else if (record.type === "normal" && afterLoc) {
619
- this.next = afterLoc;
620
- }
621
- return ContinueSentinel;
622
- },
623
- finish: function finish(finallyLoc) {
624
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
625
- var entry = this.tryEntries[i];
626
- if (entry.finallyLoc === finallyLoc) {
627
- this.complete(entry.completion, entry.afterLoc);
628
- resetTryEntry(entry);
629
- return ContinueSentinel;
630
- }
262
+ }
263
+ },
264
+ abrupt: function (t, e) {
265
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
266
+ var o = this.tryEntries[r];
267
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
268
+ var i = o;
269
+ break;
631
270
  }
632
- },
633
- "catch": function _catch(tryLoc) {
634
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
635
- var entry = this.tryEntries[i];
636
- if (entry.tryLoc === tryLoc) {
637
- var record = entry.completion;
638
- if (record.type === "throw") {
639
- var thrown = record.arg;
640
- resetTryEntry(entry);
641
- }
642
- return thrown;
271
+ }
272
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
273
+ var a = i ? i.completion : {};
274
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
275
+ },
276
+ complete: function (t, e) {
277
+ if ("throw" === t.type) throw t.arg;
278
+ 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;
279
+ },
280
+ finish: function (t) {
281
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
282
+ var r = this.tryEntries[e];
283
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
284
+ }
285
+ },
286
+ catch: function (t) {
287
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
288
+ var r = this.tryEntries[e];
289
+ if (r.tryLoc === t) {
290
+ var n = r.completion;
291
+ if ("throw" === n.type) {
292
+ var o = n.arg;
293
+ resetTryEntry(r);
643
294
  }
295
+ return o;
644
296
  }
645
-
646
- // The context.catch method must only be called with a location
647
- // argument that corresponds to a known catch block.
648
- throw new Error("illegal catch attempt");
649
- },
650
- delegateYield: function delegateYield(iterable, resultName, nextLoc) {
651
- this.delegate = {
652
- iterator: values(iterable),
653
- resultName: resultName,
654
- nextLoc: nextLoc
655
- };
656
- if (this.method === "next") {
657
- // Deliberately forget the last sent value so that we don't
658
- // accidentally pass it on to the delegate.
659
- this.arg = undefined$1;
660
- }
661
- return ContinueSentinel;
662
297
  }
663
- };
664
-
665
- // Regardless of whether this script is executing as a CommonJS module
666
- // or not, return the runtime object so that we can declare the variable
667
- // regeneratorRuntime in the outer scope, which allows this module to be
668
- // injected easily by `bin/regenerator --include-runtime script.js`.
669
- return exports;
670
- }(
671
- // If this script is executing as a CommonJS module, use module.exports
672
- // as the regeneratorRuntime namespace. Otherwise create a new empty
673
- // object. Either way, the resulting object will be used to initialize
674
- // the regeneratorRuntime variable at the top of this file.
675
- module.exports );
676
- try {
677
- regeneratorRuntime = runtime;
678
- } catch (accidentalStrictMode) {
679
- // This module should not be running in strict mode, so the above
680
- // assignment should always work unless something is misconfigured. Just
681
- // in case runtime.js accidentally runs in strict mode, in modern engines
682
- // we can explicitly access globalThis. In older engines we can escape
683
- // strict mode using a global Function call. This could conceivably fail
684
- // if a Content Security Policy forbids using Function, but in that case
685
- // the proper solution is to fix the accidental strict mode problem. If
686
- // you've misconfigured your bundler to force strict mode and applied a
687
- // CSP to forbid Function, and you're not willing to fix either of those
688
- // problems, please detail your unique predicament in a GitHub issue.
689
- if (typeof globalThis === "object") {
690
- globalThis.regeneratorRuntime = runtime;
691
- } else {
692
- Function("r", "regeneratorRuntime = r")(runtime);
298
+ throw new Error("illegal catch attempt");
299
+ },
300
+ delegateYield: function (e, r, n) {
301
+ return this.delegate = {
302
+ iterator: values(e),
303
+ resultName: r,
304
+ nextLoc: n
305
+ }, "next" === this.method && (this.arg = t), y;
693
306
  }
307
+ }, e;
308
+ }
309
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
310
+ try {
311
+ var info = gen[key](arg);
312
+ var value = info.value;
313
+ } catch (error) {
314
+ reject(error);
315
+ return;
694
316
  }
695
- });
317
+ if (info.done) {
318
+ resolve(value);
319
+ } else {
320
+ Promise.resolve(value).then(_next, _throw);
321
+ }
322
+ }
323
+ function _asyncToGenerator(fn) {
324
+ return function () {
325
+ var self = this,
326
+ args = arguments;
327
+ return new Promise(function (resolve, reject) {
328
+ var gen = fn.apply(self, args);
329
+ function _next(value) {
330
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
331
+ }
332
+ function _throw(err) {
333
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
334
+ }
335
+ _next(undefined);
336
+ });
337
+ };
338
+ }
696
339
 
340
+ var _handleCallback, _checkAlreadyLoggedUser;
697
341
  var STORAGE_USER_KEY = 'plasmic_user';
698
342
  var isBrowser = typeof window !== 'undefined';
699
343
  function getCallbackParams() {
@@ -732,219 +376,205 @@ function isContinueToSameLocation(continueTo) {
732
376
  return continueTo === pathname || continueTo === origin + pathname;
733
377
  }
734
378
  function handleCallback(_x) {
735
- return _handleCallback.apply(this, arguments);
736
- }
737
- function _handleCallback() {
738
- _handleCallback = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(opts) {
379
+ return (_handleCallback = _handleCallback || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(opts) {
739
380
  var host, appId, code, state, codeVerifier, continueTo, parsedState, result;
740
- return runtime_1.wrap(function _callee2$(_context2) {
741
- while (1) {
742
- switch (_context2.prev = _context2.next) {
743
- case 0:
744
- host = opts.host, appId = opts.appId, code = opts.code, state = opts.state, codeVerifier = opts.codeVerifier;
745
- continueTo = '/';
746
- try {
747
- if (state) {
748
- parsedState = JSON.parse(state);
749
- continueTo = parsedState.continueTo;
750
- }
751
- } catch (err) {
752
- console.error("Error while parsing state: " + err);
753
- }
754
- _context2.next = 5;
755
- return authApi.getPlasmicAppUser({
756
- host: host,
757
- appId: appId,
758
- code: code,
759
- codeVerifier: codeVerifier
760
- });
761
- case 5:
762
- result = _context2.sent;
763
- if (!result.error) {
764
- _context2.next = 9;
765
- break;
381
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
382
+ while (1) switch (_context.prev = _context.next) {
383
+ case 0:
384
+ host = opts.host, appId = opts.appId, code = opts.code, state = opts.state, codeVerifier = opts.codeVerifier;
385
+ continueTo = '/';
386
+ try {
387
+ if (state) {
388
+ parsedState = JSON.parse(state);
389
+ continueTo = parsedState.continueTo;
766
390
  }
767
- console.log("Error while performing code exchange: " + result.error);
768
- return _context2.abrupt("return", undefined);
769
- case 9:
770
- localStorage.setItem(STORAGE_USER_KEY, result.token);
771
- if (!isContinueToSameLocation(continueTo)) {
772
- window.location.assign(continueTo);
773
- } else {
774
- removeCallbackParams();
775
- }
776
- return _context2.abrupt("return", {
777
- token: result.token,
778
- user: result.user
779
- });
780
- case 12:
781
- case "end":
782
- return _context2.stop();
783
- }
391
+ } catch (err) {
392
+ console.error("Error while parsing state: " + err);
393
+ }
394
+ _context.next = 5;
395
+ return authApi.getPlasmicAppUser({
396
+ host: host,
397
+ appId: appId,
398
+ code: code,
399
+ codeVerifier: codeVerifier
400
+ });
401
+ case 5:
402
+ result = _context.sent;
403
+ if (!result.error) {
404
+ _context.next = 9;
405
+ break;
406
+ }
407
+ console.log("Error while performing code exchange: " + result.error);
408
+ return _context.abrupt("return", undefined);
409
+ case 9:
410
+ localStorage.setItem(STORAGE_USER_KEY, result.token);
411
+ if (!isContinueToSameLocation(continueTo)) {
412
+ window.location.assign(continueTo);
413
+ } else {
414
+ removeCallbackParams();
415
+ }
416
+ return _context.abrupt("return", {
417
+ token: result.token,
418
+ user: result.user
419
+ });
420
+ case 12:
421
+ case "end":
422
+ return _context.stop();
784
423
  }
785
- }, _callee2);
786
- }));
787
- return _handleCallback.apply(this, arguments);
424
+ }, _callee);
425
+ }))).apply(this, arguments);
788
426
  }
789
427
  function checkAlreadyLoggedUser(_x2) {
790
- return _checkAlreadyLoggedUser.apply(this, arguments);
428
+ return (_checkAlreadyLoggedUser = _checkAlreadyLoggedUser || _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(opts) {
429
+ var host, token, _yield$getPlasmicAppU, user, error;
430
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
431
+ while (1) switch (_context2.prev = _context2.next) {
432
+ case 0:
433
+ host = opts.host;
434
+ token = localStorage.getItem(STORAGE_USER_KEY);
435
+ if (token) {
436
+ _context2.next = 4;
437
+ break;
438
+ }
439
+ return _context2.abrupt("return", {
440
+ user: null,
441
+ token: null
442
+ });
443
+ case 4:
444
+ _context2.next = 6;
445
+ return authApi.getPlasmicAppUserFromToken({
446
+ host: host,
447
+ token: token
448
+ });
449
+ case 6:
450
+ _yield$getPlasmicAppU = _context2.sent;
451
+ user = _yield$getPlasmicAppU.user;
452
+ error = _yield$getPlasmicAppU.error;
453
+ if (!error) {
454
+ _context2.next = 13;
455
+ break;
456
+ }
457
+ // If there is an error, we just remove the token
458
+ // But ideally we should check if the reason is token expired
459
+ localStorage.removeItem(STORAGE_USER_KEY);
460
+ console.log("Error while checking logged user");
461
+ return _context2.abrupt("return", {
462
+ user: null,
463
+ token: null
464
+ });
465
+ case 13:
466
+ return _context2.abrupt("return", {
467
+ user: user,
468
+ token: token
469
+ });
470
+ case 14:
471
+ case "end":
472
+ return _context2.stop();
473
+ }
474
+ }, _callee2);
475
+ }))).apply(this, arguments);
791
476
  }
792
477
  /**
793
478
  * Handles the authentication flow for Plasmic Auth and returns the user and token
794
479
  */
795
- function _checkAlreadyLoggedUser() {
796
- _checkAlreadyLoggedUser = _asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(opts) {
797
- var host, token, _yield$getPlasmicAppU, user, error;
798
- return runtime_1.wrap(function _callee3$(_context3) {
799
- while (1) {
800
- switch (_context3.prev = _context3.next) {
480
+ function usePlasmicAuth(opts) {
481
+ var host = opts.host,
482
+ appId = opts.appId;
483
+ var authKey = "$csq$plasmic-auth-" + appId;
484
+ var _useMutablePlasmicQue = query.useMutablePlasmicQueryData(authKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
485
+ var callbackParams, codeVerifier, result;
486
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
487
+ while (1) switch (_context3.prev = _context3.next) {
801
488
  case 0:
802
- host = opts.host;
803
- token = localStorage.getItem(STORAGE_USER_KEY);
804
- if (token) {
805
- _context3.next = 4;
489
+ if (!(!appId || !isBrowser)) {
490
+ _context3.next = 2;
806
491
  break;
807
492
  }
808
493
  return _context3.abrupt("return", {
809
494
  user: null,
810
495
  token: null
811
496
  });
812
- case 4:
813
- _context3.next = 6;
814
- return authApi.getPlasmicAppUserFromToken({
497
+ case 2:
498
+ _context3.prev = 2;
499
+ // We first check if we are currently in the callback flow
500
+ callbackParams = getCallbackParams();
501
+ if (!(callbackParams.isCallbackError || callbackParams.isCodeExchange)) {
502
+ _context3.next = 27;
503
+ break;
504
+ }
505
+ if (!callbackParams.isCallbackError) {
506
+ _context3.next = 11;
507
+ break;
508
+ }
509
+ // If there is an error, we just remove the callback params
510
+ removeCallbackParams();
511
+ console.error("Error: " + callbackParams.error);
512
+ return _context3.abrupt("return", {
513
+ user: null,
514
+ token: null
515
+ });
516
+ case 11:
517
+ codeVerifier = getCodeVerifier();
518
+ if (codeVerifier) {
519
+ _context3.next = 18;
520
+ break;
521
+ }
522
+ // If there is no codeVerifier, we just remove the callback params
523
+ removeCallbackParams();
524
+ console.error('No code verifier found');
525
+ return _context3.abrupt("return", {
526
+ user: null,
527
+ token: null
528
+ });
529
+ case 18:
530
+ _context3.next = 20;
531
+ return handleCallback({
815
532
  host: host,
816
- token: token
533
+ appId: appId,
534
+ code: callbackParams.code,
535
+ state: callbackParams.state,
536
+ codeVerifier: codeVerifier
817
537
  });
818
- case 6:
819
- _yield$getPlasmicAppU = _context3.sent;
820
- user = _yield$getPlasmicAppU.user;
821
- error = _yield$getPlasmicAppU.error;
822
- if (!error) {
823
- _context3.next = 13;
538
+ case 20:
539
+ result = _context3.sent;
540
+ if (result) {
541
+ _context3.next = 24;
824
542
  break;
825
543
  }
826
- // If there is an error, we just remove the token
827
- // But ideally we should check if the reason is token expired
828
- localStorage.removeItem(STORAGE_USER_KEY);
829
- console.log("Error while checking logged user");
544
+ removeCallbackParams();
830
545
  return _context3.abrupt("return", {
831
546
  user: null,
832
547
  token: null
833
548
  });
834
- case 13:
549
+ case 24:
550
+ return _context3.abrupt("return", result);
551
+ case 25:
552
+ _context3.next = 30;
553
+ break;
554
+ case 27:
555
+ _context3.next = 29;
556
+ return checkAlreadyLoggedUser({
557
+ host: host
558
+ });
559
+ case 29:
560
+ return _context3.abrupt("return", _context3.sent);
561
+ case 30:
562
+ _context3.next = 35;
563
+ break;
564
+ case 32:
565
+ _context3.prev = 32;
566
+ _context3.t0 = _context3["catch"](2);
567
+ console.error("Error while handling auth: " + _context3.t0);
568
+ case 35:
835
569
  return _context3.abrupt("return", {
836
- user: user,
837
- token: token
570
+ user: null,
571
+ token: null
838
572
  });
839
- case 14:
573
+ case 36:
840
574
  case "end":
841
575
  return _context3.stop();
842
576
  }
843
- }
844
- }, _callee3);
845
- }));
846
- return _checkAlreadyLoggedUser.apply(this, arguments);
847
- }
848
- function usePlasmicAuth(opts) {
849
- var host = opts.host,
850
- appId = opts.appId;
851
- var authKey = "$csq$plasmic-auth-" + appId;
852
- var _useMutablePlasmicQue = query.useMutablePlasmicQueryData(authKey, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee() {
853
- var callbackParams, codeVerifier, result;
854
- return runtime_1.wrap(function _callee$(_context) {
855
- while (1) {
856
- switch (_context.prev = _context.next) {
857
- case 0:
858
- if (!(!appId || !isBrowser)) {
859
- _context.next = 2;
860
- break;
861
- }
862
- return _context.abrupt("return", {
863
- user: null,
864
- token: null
865
- });
866
- case 2:
867
- _context.prev = 2;
868
- // We first check if we are currently in the callback flow
869
- callbackParams = getCallbackParams();
870
- if (!(callbackParams.isCallbackError || callbackParams.isCodeExchange)) {
871
- _context.next = 27;
872
- break;
873
- }
874
- if (!callbackParams.isCallbackError) {
875
- _context.next = 11;
876
- break;
877
- }
878
- // If there is an error, we just remove the callback params
879
- removeCallbackParams();
880
- console.error("Error: " + callbackParams.error);
881
- return _context.abrupt("return", {
882
- user: null,
883
- token: null
884
- });
885
- case 11:
886
- codeVerifier = getCodeVerifier();
887
- if (codeVerifier) {
888
- _context.next = 18;
889
- break;
890
- }
891
- // If there is no codeVerifier, we just remove the callback params
892
- removeCallbackParams();
893
- console.error('No code verifier found');
894
- return _context.abrupt("return", {
895
- user: null,
896
- token: null
897
- });
898
- case 18:
899
- _context.next = 20;
900
- return handleCallback({
901
- host: host,
902
- appId: appId,
903
- code: callbackParams.code,
904
- state: callbackParams.state,
905
- codeVerifier: codeVerifier
906
- });
907
- case 20:
908
- result = _context.sent;
909
- if (result) {
910
- _context.next = 24;
911
- break;
912
- }
913
- removeCallbackParams();
914
- return _context.abrupt("return", {
915
- user: null,
916
- token: null
917
- });
918
- case 24:
919
- return _context.abrupt("return", result);
920
- case 25:
921
- _context.next = 30;
922
- break;
923
- case 27:
924
- _context.next = 29;
925
- return checkAlreadyLoggedUser({
926
- host: host
927
- });
928
- case 29:
929
- return _context.abrupt("return", _context.sent);
930
- case 30:
931
- _context.next = 35;
932
- break;
933
- case 32:
934
- _context.prev = 32;
935
- _context.t0 = _context["catch"](2);
936
- console.error("Error while handling auth: " + _context.t0);
937
- case 35:
938
- return _context.abrupt("return", {
939
- user: null,
940
- token: null
941
- });
942
- case 36:
943
- case "end":
944
- return _context.stop();
945
- }
946
- }
947
- }, _callee, null, [[2, 32]]);
577
+ }, _callee3, null, [[2, 32]]);
948
578
  }))),
949
579
  userData = _useMutablePlasmicQue.data,
950
580
  isLoading = _useMutablePlasmicQue.isLoading;