powr-sdk-web 4.1.16 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,7 @@ function PowrBaseActivities(_ref) {
53
53
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
54
54
  var _yield$apiCall, data, ok, _t;
55
55
  return _regenerator().w(function (_context) {
56
- while (1) switch (_context.n) {
56
+ while (1) switch (_context.p = _context.n) {
57
57
  case 0:
58
58
  setLoading(true);
59
59
  setError(null);
@@ -6,33 +6,130 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports["default"] = void 0;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _auth = require("../utils/auth");
9
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t3 in e) "default" !== _t3 && {}.hasOwnProperty.call(e, _t3) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t3)) && (i.get || i.set) ? o(f, _t3, i) : f[_t3] = e[_t3]); return f; })(e, t); }
10
- function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
11
- function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
9
+ var _firebase = require("../utils/firebase");
10
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t5 in e) "default" !== _t5 && {}.hasOwnProperty.call(e, _t5) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t5)) && (i.get || i.set) ? o(f, _t5, i) : f[_t5] = e[_t5]); return f; })(e, t); }
12
11
  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); }
13
- function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
14
- function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
15
12
  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; }
16
13
  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; }
17
14
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
15
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
16
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
17
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
18
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
19
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
20
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
20
21
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
21
22
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
22
23
  function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
23
24
  function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
24
25
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
25
26
  function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
26
- var PowrLogin = function PowrLogin(_ref) {
27
- var apiUrl = _ref.apiUrl,
28
- onLogin = _ref.onLogin,
29
- onRegister = _ref.onRegister,
30
- appName = _ref.appName,
31
- appLogo = _ref.appLogo,
32
- _ref$mode = _ref.mode,
33
- mode = _ref$mode === void 0 ? 'toggle' : _ref$mode,
34
- projectId = _ref.projectId;
35
- var _useState = (0, _react.useState)(function () {
27
+ var _useState = (0, _react.useState)(''),
28
+ _useState2 = _slicedToArray(_useState, 2),
29
+ otp = _useState2[0],
30
+ setOtp = _useState2[1];
31
+ var _useState3 = (0, _react.useState)(false),
32
+ _useState4 = _slicedToArray(_useState3, 2),
33
+ firebaseOtpSent = _useState4[0],
34
+ setFirebaseOtpSent = _useState4[1];
35
+ var _useState5 = (0, _react.useState)(null),
36
+ _useState6 = _slicedToArray(_useState5, 2),
37
+ firebaseConfirm = _useState6[0],
38
+ setFirebaseConfirm = _useState6[1];
39
+ // Firebase OTP send for phone registration
40
+ var sendFirebaseOtp = /*#__PURE__*/function () {
41
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(phone) {
42
+ var appVerifier, confirmationResult, _t;
43
+ return _regenerator().w(function (_context) {
44
+ while (1) switch (_context.p = _context.n) {
45
+ case 0:
46
+ setOtpLoading(true);
47
+ setError('');
48
+ _context.p = 1;
49
+ if (!window.recaptchaVerifier) {
50
+ window.recaptchaVerifier = new _firebase.RecaptchaVerifier('recaptcha-container', {
51
+ size: 'invisible'
52
+ }, _firebase.auth);
53
+ }
54
+ appVerifier = window.recaptchaVerifier;
55
+ _context.n = 2;
56
+ return (0, _firebase.signInWithPhoneNumber)(_firebase.auth, phone, appVerifier);
57
+ case 2:
58
+ confirmationResult = _context.v;
59
+ setFirebaseConfirm(confirmationResult);
60
+ setFirebaseOtpSent(true);
61
+ setSuccess('OTP sent to your phone!');
62
+ _context.n = 4;
63
+ break;
64
+ case 3:
65
+ _context.p = 3;
66
+ _t = _context.v;
67
+ setError('Failed to send OTP: ' + (_t.message || ''));
68
+ case 4:
69
+ _context.p = 4;
70
+ setOtpLoading(false);
71
+ return _context.f(4);
72
+ case 5:
73
+ return _context.a(2);
74
+ }
75
+ }, _callee, null, [[1, 3, 4, 5]]);
76
+ }));
77
+ return function sendFirebaseOtp(_x) {
78
+ return _ref.apply(this, arguments);
79
+ };
80
+ }();
81
+ var verifyFirebaseOtp = /*#__PURE__*/function () {
82
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
83
+ var result, _t2;
84
+ return _regenerator().w(function (_context2) {
85
+ while (1) switch (_context2.p = _context2.n) {
86
+ case 0:
87
+ setLoading(true);
88
+ setError('');
89
+ _context2.p = 1;
90
+ if (firebaseConfirm) {
91
+ _context2.n = 2;
92
+ break;
93
+ }
94
+ setError('OTP not sent yet.');
95
+ return _context2.a(2);
96
+ case 2:
97
+ _context2.n = 3;
98
+ return firebaseConfirm.confirm(otp);
99
+ case 3:
100
+ result = _context2.v;
101
+ _context2.n = 4;
102
+ return handleSubmit(null, true);
103
+ case 4:
104
+ _context2.n = 6;
105
+ break;
106
+ case 5:
107
+ _context2.p = 5;
108
+ _t2 = _context2.v;
109
+ setError('Invalid OTP. Please try again.');
110
+ case 6:
111
+ _context2.p = 6;
112
+ setLoading(false);
113
+ return _context2.f(6);
114
+ case 7:
115
+ return _context2.a(2);
116
+ }
117
+ }, _callee2, null, [[1, 5, 6, 7]]);
118
+ }));
119
+ return function verifyFirebaseOtp() {
120
+ return _ref2.apply(this, arguments);
121
+ };
122
+ }();
123
+ var PowrLogin = function PowrLogin(_ref3) {
124
+ var apiUrl = _ref3.apiUrl,
125
+ onLogin = _ref3.onLogin,
126
+ onRegister = _ref3.onRegister,
127
+ appName = _ref3.appName,
128
+ appLogo = _ref3.appLogo,
129
+ _ref3$mode = _ref3.mode,
130
+ mode = _ref3$mode === void 0 ? 'toggle' : _ref3$mode,
131
+ projectId = _ref3.projectId;
132
+ var _useState7 = (0, _react.useState)(function () {
36
133
  switch (mode) {
37
134
  case 'login':
38
135
  return true;
@@ -43,58 +140,58 @@ var PowrLogin = function PowrLogin(_ref) {
43
140
  return true;
44
141
  }
45
142
  }),
46
- _useState2 = _slicedToArray(_useState, 2),
47
- isLogin = _useState2[0],
48
- setIsLogin = _useState2[1];
49
- var _useState3 = (0, _react.useState)({
143
+ _useState8 = _slicedToArray(_useState7, 2),
144
+ isLogin = _useState8[0],
145
+ setIsLogin = _useState8[1];
146
+ var _useState9 = (0, _react.useState)({
50
147
  phoneOrEmail: '',
51
148
  password: '',
52
149
  confirmPassword: '',
53
150
  fullName: ''
54
151
  }),
55
- _useState4 = _slicedToArray(_useState3, 2),
56
- formData = _useState4[0],
57
- setFormData = _useState4[1];
58
- var _useState5 = (0, _react.useState)(false),
59
- _useState6 = _slicedToArray(_useState5, 2),
60
- loading = _useState6[0],
61
- setLoading = _useState6[1];
62
- var _useState7 = (0, _react.useState)(''),
63
- _useState8 = _slicedToArray(_useState7, 2),
64
- error = _useState8[0],
65
- setError = _useState8[1];
66
- var _useState9 = (0, _react.useState)(''),
67
152
  _useState0 = _slicedToArray(_useState9, 2),
68
- success = _useState0[0],
69
- setSuccess = _useState0[1];
70
- var _useState1 = (0, _react.useState)({}),
153
+ formData = _useState0[0],
154
+ setFormData = _useState0[1];
155
+ var _useState1 = (0, _react.useState)(false),
71
156
  _useState10 = _slicedToArray(_useState1, 2),
72
- fieldErrors = _useState10[0],
73
- setFieldErrors = _useState10[1];
74
- var _useState11 = (0, _react.useState)(false),
157
+ loading = _useState10[0],
158
+ setLoading = _useState10[1];
159
+ var _useState11 = (0, _react.useState)(''),
75
160
  _useState12 = _slicedToArray(_useState11, 2),
76
- showPassword = _useState12[0],
77
- setShowPassword = _useState12[1];
78
- var _useState13 = (0, _react.useState)(false),
161
+ error = _useState12[0],
162
+ setError = _useState12[1];
163
+ var _useState13 = (0, _react.useState)(''),
79
164
  _useState14 = _slicedToArray(_useState13, 2),
80
- showConfirmPassword = _useState14[0],
81
- setShowConfirmPassword = _useState14[1];
82
- var _useState15 = (0, _react.useState)(false),
165
+ success = _useState14[0],
166
+ setSuccess = _useState14[1];
167
+ var _useState15 = (0, _react.useState)({}),
83
168
  _useState16 = _slicedToArray(_useState15, 2),
84
- showTooltip = _useState16[0],
85
- setShowTooltip = _useState16[1];
169
+ fieldErrors = _useState16[0],
170
+ setFieldErrors = _useState16[1];
86
171
  var _useState17 = (0, _react.useState)(false),
87
172
  _useState18 = _slicedToArray(_useState17, 2),
88
- showOtpOption = _useState18[0],
89
- setShowOtpOption = _useState18[1];
173
+ showPassword = _useState18[0],
174
+ setShowPassword = _useState18[1];
90
175
  var _useState19 = (0, _react.useState)(false),
91
176
  _useState20 = _slicedToArray(_useState19, 2),
92
- otpSent = _useState20[0],
93
- setOtpSent = _useState20[1];
177
+ showConfirmPassword = _useState20[0],
178
+ setShowConfirmPassword = _useState20[1];
94
179
  var _useState21 = (0, _react.useState)(false),
95
180
  _useState22 = _slicedToArray(_useState21, 2),
96
- otpLoading = _useState22[0],
97
- setOtpLoading = _useState22[1];
181
+ showTooltip = _useState22[0],
182
+ setShowTooltip = _useState22[1];
183
+ var _useState23 = (0, _react.useState)(false),
184
+ _useState24 = _slicedToArray(_useState23, 2),
185
+ showOtpOption = _useState24[0],
186
+ setShowOtpOption = _useState24[1];
187
+ var _useState25 = (0, _react.useState)(false),
188
+ _useState26 = _slicedToArray(_useState25, 2),
189
+ otpSent = _useState26[0],
190
+ setOtpSent = _useState26[1];
191
+ var _useState27 = (0, _react.useState)(false),
192
+ _useState28 = _slicedToArray(_useState27, 2),
193
+ otpLoading = _useState28[0],
194
+ setOtpLoading = _useState28[1];
98
195
  var shouldShowToggle = mode === 'toggle';
99
196
  var handleInputChange = function handleInputChange(e) {
100
197
  var _e$target = e.target,
@@ -123,12 +220,23 @@ var PowrLogin = function PowrLogin(_ref) {
123
220
  return cleanPhone.length >= 7 && cleanPhone.length <= 15;
124
221
  };
125
222
  var handleSubmit = /*#__PURE__*/function () {
126
- var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e) {
127
- var errors, value, isEmail, endpoint, payload, _yield$apiCall, data, ok, _t;
128
- return _regenerator().w(function (_context) {
129
- while (1) switch (_context.n) {
223
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(e) {
224
+ var skipPhoneValidation,
225
+ errors,
226
+ _value,
227
+ _isEmail,
228
+ endpoint,
229
+ payload,
230
+ _yield$apiCall,
231
+ data,
232
+ ok,
233
+ _args3 = arguments,
234
+ _t3;
235
+ return _regenerator().w(function (_context3) {
236
+ while (1) switch (_context3.p = _context3.n) {
130
237
  case 0:
131
- e.preventDefault();
238
+ skipPhoneValidation = _args3.length > 1 && _args3[1] !== undefined ? _args3[1] : false;
239
+ if (e) e.preventDefault();
132
240
  setLoading(true);
133
241
  setError('');
134
242
  setSuccess('');
@@ -137,17 +245,15 @@ var PowrLogin = function PowrLogin(_ref) {
137
245
  if (!formData.phoneOrEmail.trim()) {
138
246
  errors.phoneOrEmail = 'Phone or email is required';
139
247
  } else {
140
- value = formData.phoneOrEmail.trim();
141
- isEmail = value.includes('@');
142
- if (isEmail) {
143
- if (!isValidEmail(value)) {
144
- errors.phoneOrEmail = 'Please enter a valid email address';
145
- }
146
- } else {
147
- if (!isValidPhone(value)) {
148
- errors.phoneOrEmail = 'Please enter a valid phone number';
149
- }
248
+ _value = formData.phoneOrEmail.trim();
249
+ _isEmail = _value.includes('@');
250
+ }
251
+ if (!isEmail && !skipPhoneValidation) {
252
+ if (!isValidPhone(value)) {
253
+ errors.phoneOrEmail = 'Please enter a valid phone number';
150
254
  }
255
+ } else if (isEmail && !isValidEmail(value)) {
256
+ errors.phoneOrEmail = 'Please enter a valid email address';
151
257
  }
152
258
  if (!formData.password.trim()) {
153
259
  errors.password = 'Password is required';
@@ -161,14 +267,14 @@ var PowrLogin = function PowrLogin(_ref) {
161
267
  errors.confirmPassword = 'Passwords do not match';
162
268
  }
163
269
  if (!(Object.keys(errors).length > 0)) {
164
- _context.n = 1;
270
+ _context3.n = 1;
165
271
  break;
166
272
  }
167
273
  setFieldErrors(errors);
168
274
  setLoading(false);
169
- return _context.a(2);
275
+ return _context3.a(2);
170
276
  case 1:
171
- _context.p = 1;
277
+ _context3.p = 1;
172
278
  endpoint = isLogin ? "/auth/login" : "/auth/register";
173
279
  payload = isLogin ? {
174
280
  phoneOrEmail: formData.phoneOrEmail,
@@ -178,13 +284,13 @@ var PowrLogin = function PowrLogin(_ref) {
178
284
  phoneOrEmail: formData.phoneOrEmail,
179
285
  password: formData.password
180
286
  };
181
- _context.n = 2;
287
+ _context3.n = 2;
182
288
  return (0, _auth.apiCall)(apiUrl, endpoint, projectId, {
183
289
  method: 'POST',
184
290
  body: payload
185
291
  });
186
292
  case 2:
187
- _yield$apiCall = _context.v;
293
+ _yield$apiCall = _context3.v;
188
294
  data = _yield$apiCall.data;
189
295
  ok = _yield$apiCall.ok;
190
296
  if (ok) {
@@ -215,23 +321,23 @@ var PowrLogin = function PowrLogin(_ref) {
215
321
  setError("".concat(isLogin ? 'Login' : 'Registration', " failed. Please try again."));
216
322
  }
217
323
  }
218
- _context.n = 4;
324
+ _context3.n = 4;
219
325
  break;
220
326
  case 3:
221
- _context.p = 3;
222
- _t = _context.v;
327
+ _context3.p = 3;
328
+ _t3 = _context3.v;
223
329
  setError('Network error. Please try again.');
224
330
  case 4:
225
- _context.p = 4;
331
+ _context3.p = 4;
226
332
  setLoading(false);
227
- return _context.f(4);
333
+ return _context3.f(4);
228
334
  case 5:
229
- return _context.a(2);
335
+ return _context3.a(2);
230
336
  }
231
- }, _callee, null, [[1, 3, 4, 5]]);
337
+ }, _callee3, null, [[1, 3, 4, 5]]);
232
338
  }));
233
- return function handleSubmit(_x) {
234
- return _ref2.apply(this, arguments);
339
+ return function handleSubmit(_x2) {
340
+ return _ref4.apply(this, arguments);
235
341
  };
236
342
  }();
237
343
  var toggleMode = function toggleMode() {
@@ -249,25 +355,25 @@ var PowrLogin = function PowrLogin(_ref) {
249
355
  });
250
356
  };
251
357
  var handleGetOtp = /*#__PURE__*/function () {
252
- var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
253
- var _yield$apiCall2, data, ok, _t2;
254
- return _regenerator().w(function (_context2) {
255
- while (1) switch (_context2.n) {
358
+ var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4() {
359
+ var _yield$apiCall2, data, ok, _t4;
360
+ return _regenerator().w(function (_context4) {
361
+ while (1) switch (_context4.p = _context4.n) {
256
362
  case 0:
257
363
  if (formData.phoneOrEmail.trim()) {
258
- _context2.n = 1;
364
+ _context4.n = 1;
259
365
  break;
260
366
  }
261
367
  setFieldErrors({
262
368
  phoneOrEmail: 'Phone or email is required for OTP'
263
369
  });
264
- return _context2.a(2);
370
+ return _context4.a(2);
265
371
  case 1:
266
372
  setOtpLoading(true);
267
373
  setError('');
268
374
  setFieldErrors({});
269
- _context2.p = 2;
270
- _context2.n = 3;
375
+ _context4.p = 2;
376
+ _context4.n = 3;
271
377
  return (0, _auth.apiCall)(apiUrl, "/auth/send-otp", projectId, {
272
378
  method: 'POST',
273
379
  body: {
@@ -275,7 +381,7 @@ var PowrLogin = function PowrLogin(_ref) {
275
381
  }
276
382
  });
277
383
  case 3:
278
- _yield$apiCall2 = _context2.v;
384
+ _yield$apiCall2 = _context4.v;
279
385
  data = _yield$apiCall2.data;
280
386
  ok = _yield$apiCall2.ok;
281
387
  if (ok) {
@@ -285,23 +391,23 @@ var PowrLogin = function PowrLogin(_ref) {
285
391
  } else {
286
392
  setError(data.message || 'Failed to send OTP. Please try again.');
287
393
  }
288
- _context2.n = 5;
394
+ _context4.n = 5;
289
395
  break;
290
396
  case 4:
291
- _context2.p = 4;
292
- _t2 = _context2.v;
397
+ _context4.p = 4;
398
+ _t4 = _context4.v;
293
399
  setError('Network error. Please try again.');
294
400
  case 5:
295
- _context2.p = 5;
401
+ _context4.p = 5;
296
402
  setOtpLoading(false);
297
- return _context2.f(5);
403
+ return _context4.f(5);
298
404
  case 6:
299
- return _context2.a(2);
405
+ return _context4.a(2);
300
406
  }
301
- }, _callee2, null, [[2, 4, 5, 6]]);
407
+ }, _callee4, null, [[2, 4, 5, 6]]);
302
408
  }));
303
409
  return function handleGetOtp() {
304
- return _ref3.apply(this, arguments);
410
+ return _ref5.apply(this, arguments);
305
411
  };
306
412
  }();
307
413
  return /*#__PURE__*/_react["default"].createElement("div", {
@@ -351,7 +457,39 @@ var PowrLogin = function PowrLogin(_ref) {
351
457
  required: true
352
458
  }), fieldErrors.fullName && /*#__PURE__*/_react["default"].createElement("div", {
353
459
  style: styles.fieldError
354
- }, fieldErrors.fullName)), /*#__PURE__*/_react["default"].createElement("div", {
460
+ }, fieldErrors.fullName)), !isLogin && !firebaseOtpSent && isValidPhone(formData.phoneOrEmail) && /*#__PURE__*/_react["default"].createElement("div", {
461
+ style: styles.formGroup
462
+ }, /*#__PURE__*/_react["default"].createElement("button", {
463
+ type: "button",
464
+ onClick: function onClick() {
465
+ return sendFirebaseOtp(formData.phoneOrEmail);
466
+ },
467
+ style: styles.otpButton,
468
+ disabled: otpLoading
469
+ }, otpLoading ? 'Sending OTP...' : 'Send OTP to Phone'), /*#__PURE__*/_react["default"].createElement("div", {
470
+ id: "recaptcha-container"
471
+ })), !isLogin && firebaseOtpSent && /*#__PURE__*/_react["default"].createElement("div", {
472
+ style: styles.formGroup
473
+ }, /*#__PURE__*/_react["default"].createElement("label", {
474
+ htmlFor: "otp",
475
+ style: styles.label
476
+ }, "Enter OTP"), /*#__PURE__*/_react["default"].createElement("input", {
477
+ type: "text",
478
+ id: "otp",
479
+ name: "otp",
480
+ value: otp,
481
+ onChange: function onChange(e) {
482
+ return setOtp(e.target.value);
483
+ },
484
+ style: styles.input,
485
+ placeholder: "Enter OTP received",
486
+ required: true
487
+ }), /*#__PURE__*/_react["default"].createElement("button", {
488
+ type: "button",
489
+ onClick: verifyFirebaseOtp,
490
+ style: styles.otpButton,
491
+ disabled: loading || !otp
492
+ }, loading ? 'Verifying...' : 'Verify OTP & Sign Up')), /*#__PURE__*/_react["default"].createElement("div", {
355
493
  style: styles.formGroup
356
494
  }, /*#__PURE__*/_react["default"].createElement("label", {
357
495
  htmlFor: "phoneOrEmail",
@@ -41,7 +41,7 @@ var PowrBaseBlogs = function PowrBaseBlogs(_ref) {
41
41
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
42
42
  var _yield$apiCall, data, ok, _t;
43
43
  return _regenerator().w(function (_context) {
44
- while (1) switch (_context.n) {
44
+ while (1) switch (_context.p = _context.n) {
45
45
  case 0:
46
46
  _context.p = 0;
47
47
  _context.n = 1;
@@ -94,7 +94,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
94
94
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
95
95
  var _yield$apiCall, data, ok, _t;
96
96
  return _regenerator().w(function (_context) {
97
- while (1) switch (_context.n) {
97
+ while (1) switch (_context.p = _context.n) {
98
98
  case 0:
99
99
  _context.p = 0;
100
100
  console.log('Fetching conversations...');
@@ -133,7 +133,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
133
133
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
134
134
  var _yield$apiCall2, data, ok, _t2;
135
135
  return _regenerator().w(function (_context2) {
136
- while (1) switch (_context2.n) {
136
+ while (1) switch (_context2.p = _context2.n) {
137
137
  case 0:
138
138
  _context2.p = 0;
139
139
  console.log('Fetching users...');
@@ -173,7 +173,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
173
173
  var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(userId) {
174
174
  var _yield$apiCall3, data, ok, _t3;
175
175
  return _regenerator().w(function (_context3) {
176
- while (1) switch (_context3.n) {
176
+ while (1) switch (_context3.p = _context3.n) {
177
177
  case 0:
178
178
  _context3.p = 0;
179
179
  _context3.n = 1;
@@ -215,7 +215,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
215
215
  var _ref5 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee4(conversationId) {
216
216
  var _yield$apiCall4, data, ok, _t4;
217
217
  return _regenerator().w(function (_context4) {
218
- while (1) switch (_context4.n) {
218
+ while (1) switch (_context4.p = _context4.n) {
219
219
  case 0:
220
220
  _context4.p = 0;
221
221
  setLoading(true);
@@ -259,7 +259,7 @@ var PowrBaseChat = function PowrBaseChat(_ref) {
259
259
  var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
260
260
  var _yield$apiCall5, data, ok, _t5;
261
261
  return _regenerator().w(function (_context5) {
262
- while (1) switch (_context5.n) {
262
+ while (1) switch (_context5.p = _context5.n) {
263
263
  case 0:
264
264
  if (!(!message.trim() || !selectedChat || sending)) {
265
265
  _context5.n = 1;
@@ -90,7 +90,7 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
90
90
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
91
91
  var _yield$apiCall, data, ok, sortedComments, _t;
92
92
  return _regenerator().w(function (_context) {
93
- while (1) switch (_context.n) {
93
+ while (1) switch (_context.p = _context.n) {
94
94
  case 0:
95
95
  if (contentId) {
96
96
  _context.n = 1;
@@ -141,7 +141,7 @@ var PowrBaseComments = function PowrBaseComments(_ref) {
141
141
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3() {
142
142
  var commentPayload, _yield$apiCall2, data, ok, tempNewComment, _t2;
143
143
  return _regenerator().w(function (_context3) {
144
- while (1) switch (_context3.n) {
144
+ while (1) switch (_context3.p = _context3.n) {
145
145
  case 0:
146
146
  if (!(!contentId || !newComment.trim() && selectedFiles.length === 0)) {
147
147
  _context3.n = 1;
@@ -44,7 +44,7 @@ var PowrBaseFeedsAdmin = function PowrBaseFeedsAdmin(_ref) {
44
44
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
45
45
  var _yield$apiCall, data, ok, _t;
46
46
  return _regenerator().w(function (_context) {
47
- while (1) switch (_context.n) {
47
+ while (1) switch (_context.p = _context.n) {
48
48
  case 0:
49
49
  _context.p = 0;
50
50
  _context.n = 1;
@@ -79,7 +79,7 @@ var PowrBaseFeedsAdmin = function PowrBaseFeedsAdmin(_ref) {
79
79
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
80
80
  var _yield$apiCall2, data, ok, _t2;
81
81
  return _regenerator().w(function (_context2) {
82
- while (1) switch (_context2.n) {
82
+ while (1) switch (_context2.p = _context2.n) {
83
83
  case 0:
84
84
  if (selectedPost) {
85
85
  _context2.n = 1;
@@ -58,7 +58,7 @@ var CreatePost = function CreatePost(_ref) {
58
58
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e) {
59
59
  var postData, _yield$apiCall, data, ok, _t;
60
60
  return _regenerator().w(function (_context) {
61
- while (1) switch (_context.n) {
61
+ while (1) switch (_context.p = _context.n) {
62
62
  case 0:
63
63
  e.preventDefault();
64
64
 
@@ -131,7 +131,7 @@ var CreatePost = function CreatePost(_ref) {
131
131
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(files) {
132
132
  var uploadedFiles, _iterator, _step, file, formData, _yield$apiCall2, data, ok, _t2, _t3;
133
133
  return _regenerator().w(function (_context2) {
134
- while (1) switch (_context2.n) {
134
+ while (1) switch (_context2.p = _context2.n) {
135
135
  case 0:
136
136
  uploadedFiles = [];
137
137
  _iterator = _createForOfIteratorHelper(files);
@@ -68,7 +68,7 @@ var FeedPost = function FeedPost(_ref) {
68
68
  var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
69
69
  var _yield$apiCall, data, ok, _t;
70
70
  return _regenerator().w(function (_context) {
71
- while (1) switch (_context.n) {
71
+ while (1) switch (_context.p = _context.n) {
72
72
  case 0:
73
73
  if (editContent.trim()) {
74
74
  _context.n = 1;
@@ -118,7 +118,7 @@ var FeedPost = function FeedPost(_ref) {
118
118
  var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
119
119
  var _yield$apiCall2, data, ok, _t2;
120
120
  return _regenerator().w(function (_context2) {
121
- while (1) switch (_context2.n) {
121
+ while (1) switch (_context2.p = _context2.n) {
122
122
  case 0:
123
123
  if (confirm('Are you sure you want to delete this post?')) {
124
124
  _context2.n = 1;
@@ -78,7 +78,7 @@ var PowrBaseFeed = function PowrBaseFeed(_ref) {
78
78
  _args = arguments,
79
79
  _t;
80
80
  return _regenerator().w(function (_context) {
81
- while (1) switch (_context.n) {
81
+ while (1) switch (_context.p = _context.n) {
82
82
  case 0:
83
83
  pageNum = _args.length > 0 && _args[0] !== undefined ? _args[0] : 1;
84
84
  append = _args.length > 1 && _args[1] !== undefined ? _args[1] : false;