@stokr/components-library 1.1.5 → 1.1.7

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.
Files changed (35) hide show
  1. package/dist/components/2FA/Connect2FA.js +45 -0
  2. package/dist/components/2FA/EnterCode.js +105 -0
  3. package/dist/components/2FA/EnterCode.stories.js +39 -0
  4. package/dist/components/2FA/InstallAuthApp.js +43 -0
  5. package/dist/components/2FA/ResetCode.js +47 -0
  6. package/dist/components/2FA/Sucess2FA.js +39 -0
  7. package/dist/components/2FA/disable-2fa-flow.js +232 -0
  8. package/dist/components/2FA/disable-2fa-flow.stories.js +35 -0
  9. package/dist/components/2FA/enable-2fa-flow.js +174 -0
  10. package/dist/components/2FA/enable-2fa-flow.stories.js +35 -0
  11. package/dist/components/2FA/index.js +62 -0
  12. package/dist/components/2FA/login-with-otp-flow.js +250 -0
  13. package/dist/components/2FA/login-with-otp-flow.stories.js +35 -0
  14. package/dist/components/2FA/main-flow.js +122 -0
  15. package/dist/components/2FA/main-flow.stories.js +35 -0
  16. package/dist/components/ComponentScroll/ComponentScroll.stories.js +18 -2
  17. package/dist/components/ForgotPasswordModal/ForgotPasswordModal.js +28 -11
  18. package/dist/components/Input/OtpInput.js +52 -0
  19. package/dist/components/Input/OtpInput.stories.js +63 -0
  20. package/dist/components/Layout/Layout.js +2 -1
  21. package/dist/components/RegisterAlgorand/Algorand.stories.js +5 -5
  22. package/dist/components/RegisterAlgorand/flow.js +1 -1
  23. package/dist/components/RegisterAlgorand/flowWithMemo.js +1 -1
  24. package/dist/components/StepsProgress/StepsProgress.stories.js +1 -1
  25. package/dist/components/Switch/Switch.js +17 -7
  26. package/dist/components/Text/Text.styles.js +8 -2
  27. package/dist/components/ToDoList/ToDoListTask.js +1 -1
  28. package/dist/components/taxId/TaxId.stories.js +1 -1
  29. package/dist/components/taxId/register-taxid.js +1 -1
  30. package/dist/context/Auth.js +250 -0
  31. package/dist/context/AuthContext.js +687 -0
  32. package/dist/firebase-config.js +26 -0
  33. package/dist/index.js +34 -1
  34. package/dist/static/images/background3.png +0 -0
  35. package/package.json +4 -1
@@ -0,0 +1,687 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AuthProvider = exports.AuthContext = exports.AuthConsumer = void 0;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _propTypes = _interopRequireDefault(require("prop-types"));
9
+ var _axios = _interopRequireDefault(require("../model/axios"));
10
+ var _Auth = _interopRequireDefault(require("./Auth"));
11
+ var _withRouter = require("../utils/withRouter");
12
+ var _avatarPlaceholder = _interopRequireDefault(require("../static/images/avatar-placeholder.png"));
13
+ var _auth = require("firebase/auth");
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
18
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
19
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
20
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; 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; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; 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); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { 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); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; 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; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
21
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
22
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
23
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
24
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
25
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
26
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
27
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
28
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
29
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
30
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
31
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
32
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
33
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
34
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
35
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
36
+ var AuthContext = /*#__PURE__*/_react.default.createContext();
37
+ exports.AuthContext = AuthContext;
38
+ var AuthProviderClass = /*#__PURE__*/function (_Component) {
39
+ _inherits(AuthProviderClass, _Component);
40
+ var _super = _createSuper(AuthProviderClass);
41
+ function AuthProviderClass() {
42
+ var _this;
43
+ _classCallCheck(this, AuthProviderClass);
44
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
45
+ args[_key] = arguments[_key];
46
+ }
47
+ _this = _super.call.apply(_super, [this].concat(args));
48
+ _defineProperty(_assertThisInitialized(_this), "state", {
49
+ user: undefined,
50
+ isFetchingUser: true,
51
+ avatar: _avatarPlaceholder.default,
52
+ userMfaEnrollment: null,
53
+ waitingFor2fa: false,
54
+ firebaseError: null
55
+ });
56
+ _defineProperty(_assertThisInitialized(_this), "loginUser", /*#__PURE__*/function () {
57
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(email, password) {
58
+ var user;
59
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
60
+ while (1) switch (_context.prev = _context.next) {
61
+ case 0:
62
+ _context.prev = 0;
63
+ _context.next = 3;
64
+ return _Auth.default.login(email, password);
65
+ case 3:
66
+ user = _context.sent;
67
+ console.log('🚀 ~ file: AuthContext.js:33 ~ user:', user);
68
+ _Auth.default.setAccessToken(user.accessToken);
69
+ _this.setState({
70
+ user: user,
71
+ isFetchingUser: false
72
+ });
73
+ //if you need user immediatly
74
+ return _context.abrupt("return", user);
75
+ case 10:
76
+ _context.prev = 10;
77
+ _context.t0 = _context["catch"](0);
78
+ console.log('🚀 ~ file: AuthContext.js:56 ~ error:', _context.t0);
79
+ _context.t1 = _context.t0.code;
80
+ _context.next = _context.t1 === 'auth/multi-factor-auth-required' ? 16 : _context.t1 === 'auth/requires-recent-login' ? 18 : _context.t1 === 'auth/invalid-login-credentials' ? 20 : 22;
81
+ break;
82
+ case 16:
83
+ // Initiate your second factor sign-in flow. (See next step.)
84
+ _this.setState({
85
+ waitingFor2fa: true,
86
+ firebaseError: _context.t0
87
+ });
88
+ return _context.abrupt("break", 25);
89
+ case 18:
90
+ // The user's last sign-in time does not meet the security threshold.
91
+ _this.logoutUser(false);
92
+ return _context.abrupt("break", 25);
93
+ case 20:
94
+ _context.t0.message = 'The credentials are not correct. Try again?';
95
+ throw _context.t0;
96
+ case 22:
97
+ console.log({
98
+ error: _context.t0
99
+ }); // Handle other errors, such as wrong passwords.
100
+ throw _context.t0;
101
+ case 25:
102
+ case "end":
103
+ return _context.stop();
104
+ }
105
+ }, _callee, null, [[0, 10]]);
106
+ }));
107
+ return function (_x, _x2) {
108
+ return _ref.apply(this, arguments);
109
+ };
110
+ }());
111
+ _defineProperty(_assertThisInitialized(_this), "loginUserWithTotp", /*#__PURE__*/function () {
112
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(verificationCode, error) {
113
+ var mfaResolver, selectedIndex, otpFromAuthenticator, multiFactorAssertion, userCredential, user;
114
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
115
+ while (1) switch (_context2.prev = _context2.next) {
116
+ case 0:
117
+ mfaResolver = (0, _auth.getMultiFactorResolver)((0, _auth.getAuth)(), error); // const enrolledFactors = mfaResolver.hints.map(info => info.displayName);
118
+ //console.log(enrolledFactors);
119
+ selectedIndex = 0;
120
+ _context2.t0 = mfaResolver.hints[selectedIndex].factorId;
121
+ _context2.next = _context2.t0 === _auth.TotpMultiFactorGenerator.FACTOR_ID ? 5 : _context2.t0 === _auth.PhoneMultiFactorGenerator.FACTOR_ID ? 22 : 23;
122
+ break;
123
+ case 5:
124
+ otpFromAuthenticator = verificationCode; // OTP typed by the user.
125
+ multiFactorAssertion = _auth.TotpMultiFactorGenerator.assertionForSignIn(mfaResolver.hints[selectedIndex].uid, otpFromAuthenticator);
126
+ _context2.prev = 7;
127
+ _context2.next = 10;
128
+ return mfaResolver.resolveSignIn(multiFactorAssertion);
129
+ case 10:
130
+ userCredential = _context2.sent;
131
+ user = userCredential.user;
132
+ _Auth.default.setAccessToken(user.accessToken);
133
+ _this.setState({
134
+ user: user
135
+ });
136
+ console.log('🚀 ~sucess login 2FA:');
137
+ // Successfully signed in!
138
+ _context2.next = 21;
139
+ break;
140
+ case 17:
141
+ _context2.prev = 17;
142
+ _context2.t1 = _context2["catch"](7);
143
+ // Invalid or expired OTP.
144
+ console.log({
145
+ error: _context2.t1
146
+ });
147
+ throw _context2.t1;
148
+ case 21:
149
+ return _context2.abrupt("break", 24);
150
+ case 22:
151
+ return _context2.abrupt("break", 24);
152
+ case 23:
153
+ return _context2.abrupt("break", 24);
154
+ case 24:
155
+ case "end":
156
+ return _context2.stop();
157
+ }
158
+ }, _callee2, null, [[7, 17]]);
159
+ }));
160
+ return function (_x3, _x4) {
161
+ return _ref2.apply(this, arguments);
162
+ };
163
+ }());
164
+ _defineProperty(_assertThisInitialized(_this), "generateTotpSecret", /*#__PURE__*/function () {
165
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(user) {
166
+ var appName,
167
+ multiFactorSession,
168
+ totpSecret,
169
+ totpUri,
170
+ secret,
171
+ _args3 = arguments;
172
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
173
+ while (1) switch (_context3.prev = _context3.next) {
174
+ case 0:
175
+ appName = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : 'STOKR';
176
+ _context3.prev = 1;
177
+ _context3.next = 4;
178
+ return (0, _auth.multiFactor)(user).getSession();
179
+ case 4:
180
+ multiFactorSession = _context3.sent;
181
+ _context3.next = 7;
182
+ return _auth.TotpMultiFactorGenerator.generateSecret(multiFactorSession);
183
+ case 7:
184
+ totpSecret = _context3.sent;
185
+ totpUri = totpSecret.generateQrCodeUrl(user.email, appName); // Also display this key:
186
+ secret = totpSecret.secretKey;
187
+ return _context3.abrupt("return", {
188
+ totpUri: totpUri,
189
+ totpSecret: totpSecret
190
+ });
191
+ case 13:
192
+ _context3.prev = 13;
193
+ _context3.t0 = _context3["catch"](1);
194
+ console.log('🚀 ~ file: AuthContext.js:51 ~ error:', _context3.t0);
195
+ case 16:
196
+ case "end":
197
+ return _context3.stop();
198
+ }
199
+ }, _callee3, null, [[1, 13]]);
200
+ }));
201
+ return function (_x5) {
202
+ return _ref3.apply(this, arguments);
203
+ };
204
+ }());
205
+ _defineProperty(_assertThisInitialized(_this), "unenrollUser2FA", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
206
+ var _this$state, userMfaEnrollment, user, i;
207
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
208
+ while (1) switch (_context4.prev = _context4.next) {
209
+ case 0:
210
+ _this$state = _this.state, userMfaEnrollment = _this$state.userMfaEnrollment, user = _this$state.user;
211
+ if (!((userMfaEnrollment === null || userMfaEnrollment === void 0 ? void 0 : userMfaEnrollment.length) === 0)) {
212
+ _context4.next = 4;
213
+ break;
214
+ }
215
+ console.log('User is not enrolled in 2FA');
216
+ return _context4.abrupt("return");
217
+ case 4:
218
+ _context4.prev = 4;
219
+ i = 0;
220
+ case 6:
221
+ if (!(i < userMfaEnrollment.length)) {
222
+ _context4.next = 12;
223
+ break;
224
+ }
225
+ _context4.next = 9;
226
+ return (0, _auth.multiFactor)(user).unenroll(userMfaEnrollment[i].uid);
227
+ case 9:
228
+ i++;
229
+ _context4.next = 6;
230
+ break;
231
+ case 12:
232
+ _context4.next = 19;
233
+ break;
234
+ case 14:
235
+ _context4.prev = 14;
236
+ _context4.t0 = _context4["catch"](4);
237
+ console.log({
238
+ error: _context4.t0
239
+ });
240
+ throw _context4.t0;
241
+ case 19:
242
+ case "end":
243
+ return _context4.stop();
244
+ }
245
+ }, _callee4, null, [[4, 14]]);
246
+ })));
247
+ _defineProperty(_assertThisInitialized(_this), "checkMfaEnrollment", function (user) {
248
+ var checkMfaEnrollment = (0, _auth.multiFactor)(user).enrolledFactors;
249
+ _this.setState({
250
+ userMfaEnrollment: checkMfaEnrollment
251
+ });
252
+ return checkMfaEnrollment;
253
+ });
254
+ _defineProperty(_assertThisInitialized(_this), "enrollUserToTotp", /*#__PURE__*/function () {
255
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(user, totpSecret, verificationCode, displayName) {
256
+ var multiFactorAssertion;
257
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
258
+ while (1) switch (_context5.prev = _context5.next) {
259
+ case 0:
260
+ _context5.prev = 0;
261
+ // Finalize the enrollment.
262
+ multiFactorAssertion = _auth.TotpMultiFactorGenerator.assertionForEnrollment(totpSecret, verificationCode);
263
+ _context5.next = 4;
264
+ return (0, _auth.multiFactor)(user).enroll(multiFactorAssertion, displayName);
265
+ case 4:
266
+ _context5.next = 9;
267
+ break;
268
+ case 6:
269
+ _context5.prev = 6;
270
+ _context5.t0 = _context5["catch"](0);
271
+ throw _context5.t0;
272
+ case 9:
273
+ case "end":
274
+ return _context5.stop();
275
+ }
276
+ }, _callee5, null, [[0, 6]]);
277
+ }));
278
+ return function (_x6, _x7, _x8, _x9) {
279
+ return _ref5.apply(this, arguments);
280
+ };
281
+ }());
282
+ _defineProperty(_assertThisInitialized(_this), "activateUser", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
283
+ var _yield$Auth$activateU, user, access_token;
284
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
285
+ while (1) switch (_context6.prev = _context6.next) {
286
+ case 0:
287
+ _context6.prev = 0;
288
+ _context6.next = 3;
289
+ return _Auth.default.activateUser();
290
+ case 3:
291
+ _yield$Auth$activateU = _context6.sent;
292
+ user = _yield$Auth$activateU.user;
293
+ access_token = _yield$Auth$activateU.access_token;
294
+ _axios.default.defaults.headers.common.Authorization = "Bearer ".concat(access_token);
295
+ _Auth.default.setAccessToken(access_token);
296
+ _this.setState({
297
+ user: user,
298
+ isFetchingUser: false
299
+ });
300
+ _context6.next = 16;
301
+ break;
302
+ case 11:
303
+ _context6.prev = 11;
304
+ _context6.t0 = _context6["catch"](0);
305
+ console.log('Error activating user: ', _context6.t0);
306
+ _this.props.navigate('/oops', {
307
+ state: {
308
+ message: 'This activation token has expired.',
309
+ hasActivationTokenExpired: true
310
+ }
311
+ });
312
+ _this.setState({
313
+ isFetchingUser: false
314
+ });
315
+ case 16:
316
+ case "end":
317
+ return _context6.stop();
318
+ }
319
+ }, _callee6, null, [[0, 11]]);
320
+ })));
321
+ _defineProperty(_assertThisInitialized(_this), "logoutUser", function () {
322
+ var redirect = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
323
+ _Auth.default.logout();
324
+ _this.setState({
325
+ user: null
326
+ });
327
+ if (redirect) {
328
+ window.location.href = "https://".concat(process.env.REACT_APP_WEBSITE_DOMAIN);
329
+ }
330
+ });
331
+ _defineProperty(_assertThisInitialized(_this), "getUser", /*#__PURE__*/function () {
332
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(accessToken) {
333
+ var _yield$Auth$getUser, user, userAvatar;
334
+ return _regeneratorRuntime().wrap(function _callee7$(_context7) {
335
+ while (1) switch (_context7.prev = _context7.next) {
336
+ case 0:
337
+ if (accessToken) {
338
+ _context7.next = 2;
339
+ break;
340
+ }
341
+ return _context7.abrupt("return");
342
+ case 2:
343
+ _axios.default.defaults.headers.common.Authorization = "Bearer ".concat(accessToken);
344
+ _context7.prev = 3;
345
+ _context7.next = 6;
346
+ return _Auth.default.getUser();
347
+ case 6:
348
+ _yield$Auth$getUser = _context7.sent;
349
+ user = _yield$Auth$getUser.user;
350
+ userAvatar = "".concat(process.env.REACT_APP_PHOTO_API_URL, "/media/picture/view/").concat(user._id);
351
+ _this.checkUserPhoto(userAvatar);
352
+ _this.setState({
353
+ user: user,
354
+ isFetchingUser: false
355
+ });
356
+ _context7.next = 18;
357
+ break;
358
+ case 13:
359
+ _context7.prev = 13;
360
+ _context7.t0 = _context7["catch"](3);
361
+ _this.setState({
362
+ isFetchingUser: false
363
+ });
364
+ console.log("Error fetching the user: ".concat(_context7.t0));
365
+ throw _context7.t0;
366
+ case 18:
367
+ case "end":
368
+ return _context7.stop();
369
+ }
370
+ }, _callee7, null, [[3, 13]]);
371
+ }));
372
+ return function (_x10) {
373
+ return _ref7.apply(this, arguments);
374
+ };
375
+ }());
376
+ _defineProperty(_assertThisInitialized(_this), "checkUserPhoto", function (avatar) {
377
+ try {
378
+ var http = new XMLHttpRequest();
379
+ http.open('HEAD', avatar, true);
380
+ http.onload = function () {
381
+ if (http.status === 200) {
382
+ _this.setState({
383
+ avatar: avatar
384
+ });
385
+ }
386
+ };
387
+ http.send();
388
+ } catch (error) {
389
+ console.log('error: ', error);
390
+ }
391
+ });
392
+ _defineProperty(_assertThisInitialized(_this), "checkUserIsValid", function (user) {
393
+ if ((user === null || user === void 0 ? void 0 : user.user_type) !== 'investor' && (user === null || user === void 0 ? void 0 : user.user_type) !== 'investor_entity') {
394
+ window.location.href = "https://admin.".concat(process.env.REACT_APP_WEBSITE_DOMAIN);
395
+ return false;
396
+ }
397
+ if (!(user !== null && user !== void 0 && user.country) && (user === null || user === void 0 ? void 0 : user.user_type) === 'investor') {
398
+ window.location.href = "https://signup.".concat(process.env.REACT_APP_WEBSITE_DOMAIN, "/welcome");
399
+ return false;
400
+ }
401
+ return true;
402
+ });
403
+ _defineProperty(_assertThisInitialized(_this), "uploadPhoto", function (file) {
404
+ return new Promise( /*#__PURE__*/function () {
405
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee8(resolve, reject) {
406
+ var user, formData, result;
407
+ return _regeneratorRuntime().wrap(function _callee8$(_context8) {
408
+ while (1) switch (_context8.prev = _context8.next) {
409
+ case 0:
410
+ _context8.prev = 0;
411
+ user = _this.state.user;
412
+ if (!(!user || !file)) {
413
+ _context8.next = 4;
414
+ break;
415
+ }
416
+ return _context8.abrupt("return");
417
+ case 4:
418
+ formData = new FormData();
419
+ formData.append('userId', user._id);
420
+ formData.append('file', file);
421
+ _context8.next = 9;
422
+ return _Auth.default.uploadPhoto(formData);
423
+ case 9:
424
+ result = _context8.sent;
425
+ _this.setState({
426
+ avatar: "".concat(process.env.REACT_APP_PHOTO_API_URL, "/media/picture/view/").concat(user._id, "?ignore=").concat(Date.now())
427
+ });
428
+ resolve(result);
429
+ _context8.next = 18;
430
+ break;
431
+ case 14:
432
+ _context8.prev = 14;
433
+ _context8.t0 = _context8["catch"](0);
434
+ console.log("Error: ".concat(_context8.t0));
435
+ reject(_context8.t0);
436
+ case 18:
437
+ case "end":
438
+ return _context8.stop();
439
+ }
440
+ }, _callee8, null, [[0, 14]]);
441
+ }));
442
+ return function (_x11, _x12) {
443
+ return _ref8.apply(this, arguments);
444
+ };
445
+ }());
446
+ });
447
+ _defineProperty(_assertThisInitialized(_this), "deletePhoto", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
448
+ var user, formData;
449
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
450
+ while (1) switch (_context9.prev = _context9.next) {
451
+ case 0:
452
+ user = _this.state.user;
453
+ if (user) {
454
+ _context9.next = 3;
455
+ break;
456
+ }
457
+ return _context9.abrupt("return");
458
+ case 3:
459
+ formData = new FormData();
460
+ formData.append('userId', user._id);
461
+ _context9.next = 7;
462
+ return _Auth.default.deletePhoto(formData);
463
+ case 7:
464
+ _this.setState({
465
+ avatar: undefined
466
+ });
467
+ case 8:
468
+ case "end":
469
+ return _context9.stop();
470
+ }
471
+ }, _callee9);
472
+ })));
473
+ _defineProperty(_assertThisInitialized(_this), "updateUser", /*#__PURE__*/function () {
474
+ var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(data) {
475
+ var _yield$Auth$updateUse, user;
476
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
477
+ while (1) switch (_context10.prev = _context10.next) {
478
+ case 0:
479
+ _context10.prev = 0;
480
+ _context10.next = 3;
481
+ return _Auth.default.updateUser(data);
482
+ case 3:
483
+ _yield$Auth$updateUse = _context10.sent;
484
+ user = _yield$Auth$updateUse.user;
485
+ _this.setState({
486
+ user: user
487
+ });
488
+ _context10.next = 12;
489
+ break;
490
+ case 8:
491
+ _context10.prev = 8;
492
+ _context10.t0 = _context10["catch"](0);
493
+ console.log("Error updating the user: ".concat(_context10.t0));
494
+ throw _context10.t0;
495
+ case 12:
496
+ case "end":
497
+ return _context10.stop();
498
+ }
499
+ }, _callee10, null, [[0, 8]]);
500
+ }));
501
+ return function (_x13) {
502
+ return _ref10.apply(this, arguments);
503
+ };
504
+ }());
505
+ _defineProperty(_assertThisInitialized(_this), "checkIfPrivateInvestor", /*#__PURE__*/function () {
506
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(data) {
507
+ var result;
508
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
509
+ while (1) switch (_context11.prev = _context11.next) {
510
+ case 0:
511
+ _context11.prev = 0;
512
+ _context11.next = 3;
513
+ return _Auth.default.checkPrivateInvestor(data);
514
+ case 3:
515
+ result = _context11.sent;
516
+ return _context11.abrupt("return", result);
517
+ case 7:
518
+ _context11.prev = 7;
519
+ _context11.t0 = _context11["catch"](0);
520
+ throw _context11.t0;
521
+ case 10:
522
+ case "end":
523
+ return _context11.stop();
524
+ }
525
+ }, _callee11, null, [[0, 7]]);
526
+ }));
527
+ return function (_x14) {
528
+ return _ref11.apply(this, arguments);
529
+ };
530
+ }());
531
+ _defineProperty(_assertThisInitialized(_this), "resendActivationEmail", /*#__PURE__*/function () {
532
+ var _ref12 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(data) {
533
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
534
+ while (1) switch (_context12.prev = _context12.next) {
535
+ case 0:
536
+ _context12.prev = 0;
537
+ _context12.next = 3;
538
+ return _Auth.default.resendActivationEmail(data);
539
+ case 3:
540
+ _context12.next = 9;
541
+ break;
542
+ case 5:
543
+ _context12.prev = 5;
544
+ _context12.t0 = _context12["catch"](0);
545
+ console.log("Error resending activation email: ".concat(_context12.t0));
546
+ throw _context12.t0;
547
+ case 9:
548
+ case "end":
549
+ return _context12.stop();
550
+ }
551
+ }, _callee12, null, [[0, 5]]);
552
+ }));
553
+ return function (_x15) {
554
+ return _ref12.apply(this, arguments);
555
+ };
556
+ }());
557
+ _defineProperty(_assertThisInitialized(_this), "sendWelcomeEmail", /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13() {
558
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
559
+ while (1) switch (_context13.prev = _context13.next) {
560
+ case 0:
561
+ _context13.prev = 0;
562
+ _context13.next = 3;
563
+ return _Auth.default.sendWelcomeEmail();
564
+ case 3:
565
+ _context13.next = 8;
566
+ break;
567
+ case 5:
568
+ _context13.prev = 5;
569
+ _context13.t0 = _context13["catch"](0);
570
+ console.log("Error sending welcome email: ".concat(_context13.t0));
571
+ // No need to throw error, let the app continue even if it fails
572
+ case 8:
573
+ case "end":
574
+ return _context13.stop();
575
+ }
576
+ }, _callee13, null, [[0, 5]]);
577
+ })));
578
+ _defineProperty(_assertThisInitialized(_this), "uploaProofOfAddress", /*#__PURE__*/function () {
579
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(data, ip) {
580
+ var user;
581
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
582
+ while (1) switch (_context14.prev = _context14.next) {
583
+ case 0:
584
+ _context14.prev = 0;
585
+ _context14.next = 3;
586
+ return _Auth.default.uploaProofOfAddress(data, ip);
587
+ case 3:
588
+ user = _context14.sent;
589
+ _this.setState({
590
+ user: user
591
+ });
592
+ _context14.next = 11;
593
+ break;
594
+ case 7:
595
+ _context14.prev = 7;
596
+ _context14.t0 = _context14["catch"](0);
597
+ console.log("Error uploading proof of address: ".concat(_context14.t0));
598
+ throw _context14.t0;
599
+ case 11:
600
+ case "end":
601
+ return _context14.stop();
602
+ }
603
+ }, _callee14, null, [[0, 7]]);
604
+ }));
605
+ return function (_x16, _x17) {
606
+ return _ref14.apply(this, arguments);
607
+ };
608
+ }());
609
+ _defineProperty(_assertThisInitialized(_this), "validateGreenWalletId", /*#__PURE__*/function () {
610
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(id) {
611
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
612
+ while (1) switch (_context15.prev = _context15.next) {
613
+ case 0:
614
+ _context15.prev = 0;
615
+ return _context15.abrupt("return", _Auth.default.validateGreenWalletId(id));
616
+ case 4:
617
+ _context15.prev = 4;
618
+ _context15.t0 = _context15["catch"](0);
619
+ console.log("Error validating Green Wallet ID: ".concat(_context15.t0));
620
+ throw _context15.t0;
621
+ case 8:
622
+ case "end":
623
+ return _context15.stop();
624
+ }
625
+ }, _callee15, null, [[0, 4]]);
626
+ }));
627
+ return function (_x18) {
628
+ return _ref15.apply(this, arguments);
629
+ };
630
+ }());
631
+ return _this;
632
+ }
633
+ _createClass(AuthProviderClass, [{
634
+ key: "componentDidMount",
635
+ value: function componentDidMount() {
636
+ var isActivatingUser = window.location.href.includes('/activateUser');
637
+ var accessToken = _Auth.default.getAccessToken();
638
+ if (isActivatingUser) {
639
+ this.activateUser();
640
+ } else if (accessToken) {
641
+ this.getUser(accessToken);
642
+ } else {
643
+ this.setState({
644
+ isFetchingUser: false
645
+ });
646
+ console.log('No access token');
647
+ //window.location.href = `https://${process.env.REACT_APP_WEBSITE_DOMAIN}/login`
648
+ }
649
+ }
650
+ }, {
651
+ key: "render",
652
+ value: function render() {
653
+ var children = this.props.children;
654
+ return /*#__PURE__*/_react.default.createElement(AuthContext.Provider, {
655
+ value: _objectSpread(_objectSpread({}, this.state), {}, {
656
+ checkUserIsValid: this.checkUserIsValid,
657
+ checkUserPhoto: this.checkUserPhoto,
658
+ uploadPhoto: this.uploadPhoto,
659
+ deletePhoto: this.deletePhoto,
660
+ unenrollUser2FA: this.unenrollUser2FA,
661
+ loginUserWithTotp: this.loginUserWithTotp,
662
+ checkMfaEnrollment: this.checkMfaEnrollment,
663
+ generateTotpSecret: this.generateTotpSecret,
664
+ enrollUserToTotp: this.enrollUserToTotp,
665
+ loginUser: this.loginUser,
666
+ logoutUser: this.logoutUser,
667
+ getUser: this.getUser,
668
+ updateUser: this.updateUser,
669
+ checkIfPrivateInvestor: this.checkIfPrivateInvestor,
670
+ sendWelcomeEmail: this.sendWelcomeEmail,
671
+ resendActivationEmail: this.resendActivationEmail,
672
+ uploaProofOfAddress: this.uploaProofOfAddress,
673
+ validateGreenWalletId: this.validateGreenWalletId
674
+ })
675
+ }, children);
676
+ }
677
+ }]);
678
+ return AuthProviderClass;
679
+ }(_react.Component);
680
+ AuthProviderClass.propTypes = {
681
+ children: _propTypes.default.node.isRequired
682
+ };
683
+ var AuthConsumer = AuthContext.Consumer;
684
+ exports.AuthConsumer = AuthConsumer;
685
+ var AuthProvider = (0, _withRouter.withRouter)(AuthProviderClass);
686
+ //export default AuthProvider
687
+ exports.AuthProvider = AuthProvider;