powr-sdk-web 4.4.1 → 4.4.2
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.
- package/dist/auth/index.js +109 -82
- package/package.json +1 -1
package/dist/auth/index.js
CHANGED
|
@@ -7,7 +7,7 @@ exports["default"] = void 0;
|
|
|
7
7
|
var _react = _interopRequireWildcard(require("react"));
|
|
8
8
|
var _auth = require("../utils/auth");
|
|
9
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
|
|
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 _t6 in e) "default" !== _t6 && {}.hasOwnProperty.call(e, _t6) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t6)) && (i.get || i.set) ? o(f, _t6, i) : f[_t6] = e[_t6]); return f; })(e, t); }
|
|
11
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); }
|
|
12
12
|
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 }; })(); }
|
|
13
13
|
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); }
|
|
@@ -116,6 +116,14 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
116
116
|
_useState28 = _slicedToArray(_useState27, 2),
|
|
117
117
|
firebaseConfirm = _useState28[0],
|
|
118
118
|
setFirebaseConfirm = _useState28[1];
|
|
119
|
+
var _useState29 = (0, _react.useState)(false),
|
|
120
|
+
_useState30 = _slicedToArray(_useState29, 2),
|
|
121
|
+
showOtpModal = _useState30[0],
|
|
122
|
+
setShowOtpModal = _useState30[1];
|
|
123
|
+
var _useState31 = (0, _react.useState)(false),
|
|
124
|
+
_useState32 = _slicedToArray(_useState31, 2),
|
|
125
|
+
isPhoneVerified = _useState32[0],
|
|
126
|
+
setIsPhoneVerified = _useState32[1];
|
|
119
127
|
var shouldShowToggle = mode === 'toggle';
|
|
120
128
|
var handleInputChange = /*#__PURE__*/function () {
|
|
121
129
|
var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(e) {
|
|
@@ -195,6 +203,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
195
203
|
confirmationResult = _context2.v;
|
|
196
204
|
setFirebaseConfirm(confirmationResult);
|
|
197
205
|
setFirebaseOtpSent(true);
|
|
206
|
+
setShowOtpModal(true);
|
|
198
207
|
setSuccess('OTP sent to your phone!');
|
|
199
208
|
_context2.n = 8;
|
|
200
209
|
break;
|
|
@@ -260,23 +269,24 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
260
269
|
return firebaseConfirm.confirm(otp);
|
|
261
270
|
case 3:
|
|
262
271
|
result = _context3.v;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
272
|
+
setIsPhoneVerified(true);
|
|
273
|
+
setShowOtpModal(false);
|
|
274
|
+
setSuccess('Phone number verified successfully! Now you can sign up.');
|
|
275
|
+
setOtp('');
|
|
276
|
+
_context3.n = 5;
|
|
267
277
|
break;
|
|
268
|
-
case
|
|
269
|
-
_context3.p =
|
|
278
|
+
case 4:
|
|
279
|
+
_context3.p = 4;
|
|
270
280
|
_t3 = _context3.v;
|
|
271
281
|
setError('Invalid OTP. Please try again.');
|
|
272
|
-
case
|
|
273
|
-
_context3.p =
|
|
282
|
+
case 5:
|
|
283
|
+
_context3.p = 5;
|
|
274
284
|
setLoading(false);
|
|
275
|
-
return _context3.f(
|
|
276
|
-
case
|
|
285
|
+
return _context3.f(5);
|
|
286
|
+
case 6:
|
|
277
287
|
return _context3.a(2);
|
|
278
288
|
}
|
|
279
|
-
}, _callee3, null, [[1, 5, 6
|
|
289
|
+
}, _callee3, null, [[1, 4, 5, 6]]);
|
|
280
290
|
}));
|
|
281
291
|
return function verifyFirebaseOtp() {
|
|
282
292
|
return _ref4.apply(this, arguments);
|
|
@@ -306,8 +316,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
306
316
|
data,
|
|
307
317
|
ok,
|
|
308
318
|
_args4 = arguments,
|
|
309
|
-
_t4
|
|
310
|
-
_t5;
|
|
319
|
+
_t4;
|
|
311
320
|
return _regenerator().w(function (_context4) {
|
|
312
321
|
while (1) switch (_context4.p = _context4.n) {
|
|
313
322
|
case 0:
|
|
@@ -348,8 +357,8 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
348
357
|
if (!isLogin && formData.password !== formData.confirmPassword) {
|
|
349
358
|
errors.confirmPassword = 'Passwords do not match';
|
|
350
359
|
}
|
|
351
|
-
if (!isLogin &&
|
|
352
|
-
errors.
|
|
360
|
+
if (!isLogin && !isPhoneVerified) {
|
|
361
|
+
errors.phoneOrEmail = 'Please verify your phone number first';
|
|
353
362
|
}
|
|
354
363
|
if (!(Object.keys(errors).length > 0)) {
|
|
355
364
|
_context4.n = 1;
|
|
@@ -359,35 +368,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
359
368
|
setLoading(false);
|
|
360
369
|
return _context4.a(2);
|
|
361
370
|
case 1:
|
|
362
|
-
|
|
363
|
-
_context4.n = 7;
|
|
364
|
-
break;
|
|
365
|
-
}
|
|
366
|
-
_context4.p = 2;
|
|
367
|
-
if (!(firebaseConfirm && otp)) {
|
|
368
|
-
_context4.n = 4;
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
_context4.n = 3;
|
|
372
|
-
return firebaseConfirm.confirm(otp);
|
|
373
|
-
case 3:
|
|
374
|
-
_context4.n = 5;
|
|
375
|
-
break;
|
|
376
|
-
case 4:
|
|
377
|
-
setError('Please verify OTP before signing up');
|
|
378
|
-
setLoading(false);
|
|
379
|
-
return _context4.a(2);
|
|
380
|
-
case 5:
|
|
381
|
-
_context4.n = 7;
|
|
382
|
-
break;
|
|
383
|
-
case 6:
|
|
384
|
-
_context4.p = 6;
|
|
385
|
-
_t4 = _context4.v;
|
|
386
|
-
setError('Invalid OTP. Please try again.');
|
|
387
|
-
setLoading(false);
|
|
388
|
-
return _context4.a(2);
|
|
389
|
-
case 7:
|
|
390
|
-
_context4.p = 7;
|
|
371
|
+
_context4.p = 1;
|
|
391
372
|
endpoint = isLogin ? "/auth/login" : "/auth/register";
|
|
392
373
|
payload = isLogin ? {
|
|
393
374
|
phoneOrEmail: formData.phoneOrEmail,
|
|
@@ -397,12 +378,12 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
397
378
|
phoneOrEmail: formData.phoneOrEmail,
|
|
398
379
|
password: formData.password
|
|
399
380
|
};
|
|
400
|
-
_context4.n =
|
|
381
|
+
_context4.n = 2;
|
|
401
382
|
return (0, _auth.apiCall)(apiUrl, endpoint, projectId, {
|
|
402
383
|
method: 'POST',
|
|
403
384
|
body: payload
|
|
404
385
|
});
|
|
405
|
-
case
|
|
386
|
+
case 2:
|
|
406
387
|
_yield$apiCall = _context4.v;
|
|
407
388
|
data = _yield$apiCall.data;
|
|
408
389
|
ok = _yield$apiCall.ok;
|
|
@@ -438,20 +419,20 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
438
419
|
setError("".concat(isLogin ? 'Login' : 'Registration', " failed. Please try again."));
|
|
439
420
|
}
|
|
440
421
|
}
|
|
441
|
-
_context4.n =
|
|
422
|
+
_context4.n = 4;
|
|
442
423
|
break;
|
|
443
|
-
case
|
|
444
|
-
_context4.p =
|
|
445
|
-
|
|
424
|
+
case 3:
|
|
425
|
+
_context4.p = 3;
|
|
426
|
+
_t4 = _context4.v;
|
|
446
427
|
setError('Network error. Please try again.');
|
|
447
|
-
case
|
|
448
|
-
_context4.p =
|
|
428
|
+
case 4:
|
|
429
|
+
_context4.p = 4;
|
|
449
430
|
setLoading(false);
|
|
450
|
-
return _context4.f(
|
|
451
|
-
case
|
|
431
|
+
return _context4.f(4);
|
|
432
|
+
case 5:
|
|
452
433
|
return _context4.a(2);
|
|
453
434
|
}
|
|
454
|
-
}, _callee4, null, [[
|
|
435
|
+
}, _callee4, null, [[1, 3, 4, 5]]);
|
|
455
436
|
}));
|
|
456
437
|
return function handleSubmit(_x3) {
|
|
457
438
|
return _ref5.apply(this, arguments);
|
|
@@ -467,6 +448,8 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
467
448
|
setOtp('');
|
|
468
449
|
setFirebaseOtpSent(false);
|
|
469
450
|
setFirebaseConfirm(null);
|
|
451
|
+
setShowOtpModal(false);
|
|
452
|
+
setIsPhoneVerified(false);
|
|
470
453
|
setFormData({
|
|
471
454
|
phoneOrEmail: '',
|
|
472
455
|
password: '',
|
|
@@ -476,7 +459,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
476
459
|
};
|
|
477
460
|
var handleGetOtp = /*#__PURE__*/function () {
|
|
478
461
|
var _ref6 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee5() {
|
|
479
|
-
var _yield$apiCall2, data, ok,
|
|
462
|
+
var _yield$apiCall2, data, ok, _t5;
|
|
480
463
|
return _regenerator().w(function (_context5) {
|
|
481
464
|
while (1) switch (_context5.p = _context5.n) {
|
|
482
465
|
case 0:
|
|
@@ -515,7 +498,7 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
515
498
|
break;
|
|
516
499
|
case 4:
|
|
517
500
|
_context5.p = 4;
|
|
518
|
-
|
|
501
|
+
_t5 = _context5.v;
|
|
519
502
|
setError('Network error. Please try again.');
|
|
520
503
|
case 5:
|
|
521
504
|
_context5.p = 5;
|
|
@@ -595,35 +578,20 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
595
578
|
style: styles.fieldError
|
|
596
579
|
}, fieldErrors.phoneOrEmail), !isLogin && /*#__PURE__*/_react["default"].createElement("div", {
|
|
597
580
|
style: styles.helpText
|
|
598
|
-
}, "Registration requires phone verification for security"), !isLogin && isValidPhone(formData.phoneOrEmail) &&
|
|
581
|
+
}, "Registration requires phone verification for security"), !isLogin && isValidPhone(formData.phoneOrEmail) && !isPhoneVerified && /*#__PURE__*/_react["default"].createElement("button", {
|
|
599
582
|
type: "button",
|
|
600
583
|
onClick: function onClick() {
|
|
601
584
|
return sendFirebaseOtp(formatPhone(formData.phoneOrEmail));
|
|
602
585
|
},
|
|
603
|
-
style: styles.otpButton,
|
|
586
|
+
style: _objectSpread(_objectSpread({}, styles.otpButton), {}, {
|
|
587
|
+
marginTop: '8px'
|
|
588
|
+
}),
|
|
604
589
|
disabled: otpLoading
|
|
605
|
-
}, otpLoading ? 'Sending OTP...' : '
|
|
590
|
+
}, otpLoading ? 'Sending OTP...' : 'Verify Phone Number'), !isLogin && isPhoneVerified && /*#__PURE__*/_react["default"].createElement("div", {
|
|
591
|
+
style: styles.successText
|
|
592
|
+
}, "\u2705 Phone number verified successfully!"), /*#__PURE__*/_react["default"].createElement("div", {
|
|
606
593
|
id: "recaptcha-container"
|
|
607
|
-
}))
|
|
608
|
-
htmlFor: "otp",
|
|
609
|
-
style: styles.label
|
|
610
|
-
}, "Enter OTP"), /*#__PURE__*/_react["default"].createElement("input", {
|
|
611
|
-
type: "text",
|
|
612
|
-
id: "otp",
|
|
613
|
-
name: "otp",
|
|
614
|
-
value: otp,
|
|
615
|
-
onChange: function onChange(e) {
|
|
616
|
-
return setOtp(e.target.value);
|
|
617
|
-
},
|
|
618
|
-
style: styles.input,
|
|
619
|
-
placeholder: "Enter OTP received",
|
|
620
|
-
required: true
|
|
621
|
-
}), /*#__PURE__*/_react["default"].createElement("button", {
|
|
622
|
-
type: "button",
|
|
623
|
-
onClick: verifyFirebaseOtp,
|
|
624
|
-
style: styles.otpButton,
|
|
625
|
-
disabled: loading || !otp
|
|
626
|
-
}, loading ? 'Verifying...' : 'Verify OTP & Sign Up')))), /*#__PURE__*/_react["default"].createElement("div", {
|
|
594
|
+
})), /*#__PURE__*/_react["default"].createElement("div", {
|
|
627
595
|
style: styles.formGroup
|
|
628
596
|
}, /*#__PURE__*/_react["default"].createElement("label", {
|
|
629
597
|
htmlFor: "password",
|
|
@@ -737,7 +705,55 @@ var PowrLogin = function PowrLogin(_ref) {
|
|
|
737
705
|
}, "Sign in here") : /*#__PURE__*/_react["default"].createElement("a", {
|
|
738
706
|
href: "/login",
|
|
739
707
|
style: styles.navigationLink
|
|
740
|
-
}, "Sign in here")))))
|
|
708
|
+
}, "Sign in here"))))), showOtpModal && /*#__PURE__*/_react["default"].createElement("div", {
|
|
709
|
+
style: styles.modalOverlay
|
|
710
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
711
|
+
style: styles.modalContent
|
|
712
|
+
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
713
|
+
style: styles.modalHeader
|
|
714
|
+
}, /*#__PURE__*/_react["default"].createElement("h2", {
|
|
715
|
+
style: styles.modalTitle
|
|
716
|
+
}, "Verify Phone Number"), /*#__PURE__*/_react["default"].createElement("button", {
|
|
717
|
+
onClick: function onClick() {
|
|
718
|
+
setShowOtpModal(false);
|
|
719
|
+
setOtp('');
|
|
720
|
+
setError('');
|
|
721
|
+
},
|
|
722
|
+
style: styles.closeButton
|
|
723
|
+
}, "\xD7")), /*#__PURE__*/_react["default"].createElement("p", {
|
|
724
|
+
style: styles.modalText
|
|
725
|
+
}, "We've sent a verification code to ", /*#__PURE__*/_react["default"].createElement("strong", null, formData.phoneOrEmail)), /*#__PURE__*/_react["default"].createElement("div", {
|
|
726
|
+
style: styles.formGroup
|
|
727
|
+
}, /*#__PURE__*/_react["default"].createElement("label", {
|
|
728
|
+
htmlFor: "modalOtp",
|
|
729
|
+
style: styles.label
|
|
730
|
+
}, "Enter OTP"), /*#__PURE__*/_react["default"].createElement("input", {
|
|
731
|
+
type: "text",
|
|
732
|
+
id: "modalOtp",
|
|
733
|
+
value: otp,
|
|
734
|
+
onChange: function onChange(e) {
|
|
735
|
+
return setOtp(e.target.value);
|
|
736
|
+
},
|
|
737
|
+
style: styles.input,
|
|
738
|
+
placeholder: "Enter 6-digit OTP",
|
|
739
|
+
maxLength: "6",
|
|
740
|
+
autoFocus: true
|
|
741
|
+
})), error && /*#__PURE__*/_react["default"].createElement("div", {
|
|
742
|
+
style: styles.errorMessage
|
|
743
|
+
}, error), /*#__PURE__*/_react["default"].createElement("div", {
|
|
744
|
+
style: styles.modalButtons
|
|
745
|
+
}, /*#__PURE__*/_react["default"].createElement("button", {
|
|
746
|
+
onClick: function onClick() {
|
|
747
|
+
setShowOtpModal(false);
|
|
748
|
+
setOtp('');
|
|
749
|
+
setError('');
|
|
750
|
+
},
|
|
751
|
+
style: styles.cancelButton
|
|
752
|
+
}, "Cancel"), /*#__PURE__*/_react["default"].createElement("button", {
|
|
753
|
+
onClick: verifyFirebaseOtp,
|
|
754
|
+
disabled: loading || !otp || otp.length < 6,
|
|
755
|
+
style: _objectSpread(_objectSpread({}, styles.button), loading || !otp || otp.length < 6 ? styles.buttonDisabled : {})
|
|
756
|
+
}, loading ? 'Verifying...' : 'Verify')))));
|
|
741
757
|
};
|
|
742
758
|
var styles = {
|
|
743
759
|
container: {
|
|
@@ -878,6 +894,17 @@ var styles = {
|
|
|
878
894
|
fontSize: '14px',
|
|
879
895
|
fontWeight: '500'
|
|
880
896
|
},
|
|
897
|
+
successText: {
|
|
898
|
+
background: '#f0fdf4',
|
|
899
|
+
color: '#16a34a',
|
|
900
|
+
padding: '8px 12px',
|
|
901
|
+
borderRadius: '6px',
|
|
902
|
+
border: '1px solid #bbf7d0',
|
|
903
|
+
fontSize: '12px',
|
|
904
|
+
fontWeight: '500',
|
|
905
|
+
marginTop: '8px',
|
|
906
|
+
textAlign: 'center'
|
|
907
|
+
},
|
|
881
908
|
toggleSection: {
|
|
882
909
|
marginTop: '24px',
|
|
883
910
|
textAlign: 'center',
|