@basiq/connect-auth 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -923,6 +923,8 @@ function StartScreen(props) {
923
923
  shadow = props.shadow,
924
924
  authRequestId = props.authRequestId,
925
925
  showErrorScreen = props.showErrorScreen,
926
+ smsSent = props.smsSent,
927
+ setSmsSent = props.setSmsSent,
926
928
  test = props.test;
927
929
  var _useState = useState(false),
928
930
  loading = _useState[0],
@@ -946,8 +948,8 @@ function StartScreen(props) {
946
948
  while (1) switch (_context.prev = _context.next) {
947
949
  case 0:
948
950
  setLoading(true);
949
- if (!authRequestId) {
950
- _context.next = 6;
951
+ if (!(authRequestId && !smsSent)) {
952
+ _context.next = 8;
951
953
  break;
952
954
  }
953
955
  _context.next = 4;
@@ -958,12 +960,20 @@ function StartScreen(props) {
958
960
  case 4:
959
961
  response = _context.sent;
960
962
  if (response != null && response.ok) {
963
+ setSmsSent(true);
961
964
  setLoading(false);
962
965
  onContinue();
963
966
  } else {
964
967
  showErrorScreen(response == null ? void 0 : response.statusCode.toString());
965
968
  }
966
- case 6:
969
+ _context.next = 9;
970
+ break;
971
+ case 8:
972
+ if (smsSent) {
973
+ setLoading(false);
974
+ onContinue();
975
+ }
976
+ case 9:
967
977
  case "end":
968
978
  return _context.stop();
969
979
  }
@@ -1053,6 +1063,9 @@ function AuthScreen(_ref) {
1053
1063
  var _useState5 = useState(false),
1054
1064
  loading = _useState5[0],
1055
1065
  setLoading = _useState5[1];
1066
+ var _useState6 = useState(false),
1067
+ tooManyAttemps = _useState6[0],
1068
+ setTooManyAttemps = _useState6[1];
1056
1069
  var handleCodeApply = useCallback( /*#__PURE__*/function () {
1057
1070
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(e) {
1058
1071
  var _response$data, response, _response$data2;
@@ -1060,7 +1073,7 @@ function AuthScreen(_ref) {
1060
1073
  while (1) switch (_context.prev = _context.next) {
1061
1074
  case 0:
1062
1075
  if (!(smsCode.length === 4 && error.length === 0 && (!e || (e == null ? void 0 : e.key) === 'Enter'))) {
1063
- _context.next = 7;
1076
+ _context.next = 6;
1064
1077
  break;
1065
1078
  }
1066
1079
  setLoading(true);
@@ -1074,12 +1087,15 @@ function AuthScreen(_ref) {
1074
1087
  response = _context.sent;
1075
1088
  if (response != null && (_response$data = response.data) != null && _response$data.access_token) {
1076
1089
  window.open("https://consent.basiq.io/home?token=" + (response == null || (_response$data2 = response.data) == null ? void 0 : _response$data2.access_token) + "&action=" + (action.length > 0 ? action : 'connect'), "_self");
1077
- }
1078
- if (response != null && response.error) {
1090
+ } else if ((response == null ? void 0 : response.statusCode) === 204) {
1091
+ setLoading(false);
1092
+ setTooManyAttemps(true);
1093
+ setError(t('too_many_attempts'));
1094
+ } else if (response != null && response.error) {
1079
1095
  setLoading(false);
1080
1096
  setError(t('this_code_doesnt_appear_to_be_valid'));
1081
1097
  }
1082
- case 7:
1098
+ case 6:
1083
1099
  case "end":
1084
1100
  return _context.stop();
1085
1101
  }
@@ -1153,14 +1169,15 @@ function AuthScreen(_ref) {
1153
1169
  onChange: handleInput,
1154
1170
  value: smsCode,
1155
1171
  filled: smsCode.length === 4,
1156
- error: !!error,
1172
+ error: tooManyAttemps || !!error,
1173
+ disabled: tooManyAttemps,
1157
1174
  onKeyPress: function onKeyPress(e) {
1158
1175
  return handleCodeApply(e);
1159
1176
  }
1160
1177
  })), React.createElement(PageConnectFooterControl, null, resend && React.createElement(StatusMessage, null, t('new_sms_code_has_been_sent')), !!error && React.createElement(StatusMessage, {
1161
1178
  error: true
1162
1179
  }, error), React.createElement(PageConnectFooterText, null, React.createElement("span", null, React.createElement(React.Fragment, null, t('didnt_receive_the_code'), " ", React.createElement(DivAsLink, {
1163
- disabled: resendLoading,
1180
+ disabled: tooManyAttemps || resendLoading,
1164
1181
  onClick: function onClick() {
1165
1182
  return !resendLoading && handleResend();
1166
1183
  }
@@ -1199,6 +1216,9 @@ function App(props) {
1199
1216
  var _useState9 = useState(''),
1200
1217
  errorCode = _useState9[0],
1201
1218
  setErrorCode = _useState9[1];
1219
+ var _useState10 = useState(false),
1220
+ smsSent = _useState10[0],
1221
+ setSmsSent = _useState10[1];
1202
1222
  var handleConnectionsScroll = function handleConnectionsScroll(event) {
1203
1223
  setShadow(detectScrollToBottom(event));
1204
1224
  };
@@ -1280,6 +1300,8 @@ function App(props) {
1280
1300
  return setCurrentScreen(2);
1281
1301
  },
1282
1302
  authRequestId: authId,
1303
+ smsSent: smsSent,
1304
+ setSmsSent: setSmsSent,
1283
1305
  test: test
1284
1306
  });
1285
1307
  case 2:
@@ -1338,6 +1360,7 @@ var resend_sms = "Resend SMS";
1338
1360
  var failed_to_send_sms = "Failed to send SMS.";
1339
1361
  var page_not_found = "Page not found";
1340
1362
  var missing_authentication_token = "Missing Authentication Token";
1363
+ var too_many_attempts = "Too many attempts. Please use a new link to try again.";
1341
1364
  var translationEN = {
1342
1365
  back: back,
1343
1366
  error: error,
@@ -1365,7 +1388,8 @@ var translationEN = {
1365
1388
  resend_sms: resend_sms,
1366
1389
  failed_to_send_sms: failed_to_send_sms,
1367
1390
  page_not_found: page_not_found,
1368
- missing_authentication_token: missing_authentication_token
1391
+ missing_authentication_token: missing_authentication_token,
1392
+ too_many_attempts: too_many_attempts
1369
1393
  };
1370
1394
 
1371
1395
  // the translations