dauth-context-react 0.2.100 → 0.2.102

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.
@@ -377,7 +377,9 @@ var initialDauthState = {
377
377
  },
378
378
  isLoading: false
379
379
  },
380
- sendEmailVerification: function sendEmailVerification() {}
380
+ sendEmailVerification: function sendEmailVerification() {
381
+ return Promise.resolve(false);
382
+ }
381
383
  };
382
384
 
383
385
  var LOGIN = 'LOGIN';
@@ -521,7 +523,7 @@ var updateUserAPI = /*#__PURE__*/function () {
521
523
  _context2.next = 3;
522
524
  return fetch(getServerBasePath({
523
525
  domainName: domainName
524
- }) + "\n /" + routes.tenantUpdateUser + "\n /" + domainName, params);
526
+ }) + "/" + routes.tenantUpdateUser + "/" + domainName, params);
525
527
  case 3:
526
528
  response = _context2.sent;
527
529
  _context2.next = 6;
@@ -762,111 +764,96 @@ function _setAutoLoginAction() {
762
764
  }));
763
765
  return _setAutoLoginAction.apply(this, arguments);
764
766
  }
765
- function setLogoutAction(_x3) {
766
- return _setLogoutAction.apply(this, arguments);
767
- }
768
- function _setLogoutAction() {
769
- _setLogoutAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
770
- var dispatch;
771
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
772
- while (1) switch (_context3.prev = _context3.next) {
773
- case 0:
774
- dispatch = _ref3.dispatch;
775
- dispatch({
776
- type: SET_IS_LOADING,
777
- payload: {
778
- isLoading: true
779
- }
780
- });
781
- dispatch({
782
- type: LOGIN,
783
- payload: {
784
- user: {
785
- language: window.document.documentElement.getAttribute('lang') || 'es'
786
- },
787
- domain: {},
788
- isAuthenticated: false
789
- }
790
- });
791
- localStorage.removeItem(TOKEN_LS);
792
- return _context3.abrupt("return", dispatch({
793
- type: SET_IS_LOADING,
794
- payload: {
795
- isLoading: false
796
- }
797
- }));
798
- case 5:
799
- case "end":
800
- return _context3.stop();
801
- }
802
- }, _callee3);
803
- }));
804
- return _setLogoutAction.apply(this, arguments);
767
+ function setLogoutAction(_ref3) {
768
+ var dispatch = _ref3.dispatch;
769
+ dispatch({
770
+ type: SET_IS_LOADING,
771
+ payload: {
772
+ isLoading: true
773
+ }
774
+ });
775
+ dispatch({
776
+ type: LOGIN,
777
+ payload: {
778
+ user: {
779
+ language: window.document.documentElement.getAttribute('lang') || 'es'
780
+ },
781
+ domain: {},
782
+ isAuthenticated: false
783
+ }
784
+ });
785
+ localStorage.removeItem(TOKEN_LS);
786
+ return dispatch({
787
+ type: SET_IS_LOADING,
788
+ payload: {
789
+ isLoading: false
790
+ }
791
+ });
805
792
  }
806
- function setUpdateUserAction(_x4) {
793
+ function setUpdateUserAction(_x3) {
807
794
  return _setUpdateUserAction.apply(this, arguments);
808
795
  }
809
796
  function _setUpdateUserAction() {
810
- _setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref4) {
797
+ _setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
811
798
  var dispatch, domainName, user, token, getUserFetch;
812
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
813
- while (1) switch (_context4.prev = _context4.next) {
799
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
800
+ while (1) switch (_context3.prev = _context3.next) {
814
801
  case 0:
815
802
  dispatch = _ref4.dispatch, domainName = _ref4.domainName, user = _ref4.user, token = _ref4.token;
816
803
  if (user.language) {
817
804
  window.document.documentElement.setAttribute('lang', user.language);
818
805
  }
819
806
  if (token) {
820
- _context4.next = 5;
807
+ _context3.next = 5;
821
808
  break;
822
809
  }
823
810
  dispatch({
824
811
  type: UPDATE_USER,
825
812
  payload: user
826
813
  });
827
- return _context4.abrupt("return", false);
814
+ return _context3.abrupt("return", false);
828
815
  case 5:
829
- _context4.prev = 5;
830
- _context4.next = 8;
816
+ _context3.prev = 5;
817
+ _context3.next = 8;
831
818
  return updateUserAPI(domainName, user, token);
832
819
  case 8:
833
- getUserFetch = _context4.sent;
820
+ getUserFetch = _context3.sent;
834
821
  if (!(getUserFetch.response.status === 200)) {
835
- _context4.next = 14;
822
+ _context3.next = 14;
836
823
  break;
837
824
  }
838
825
  dispatch({
839
826
  type: UPDATE_USER,
840
827
  payload: getUserFetch.data.user
841
828
  });
842
- return _context4.abrupt("return", true);
829
+ return _context3.abrupt("return", true);
843
830
  case 14:
844
831
  console.log('Update user error', getUserFetch.data.message);
845
- return _context4.abrupt("return", false);
832
+ return _context3.abrupt("return", false);
846
833
  case 16:
847
- _context4.next = 22;
834
+ _context3.next = 22;
848
835
  break;
849
836
  case 18:
850
- _context4.prev = 18;
851
- _context4.t0 = _context4["catch"](5);
852
- console.log('Update user error', _context4.t0);
853
- return _context4.abrupt("return", false);
837
+ _context3.prev = 18;
838
+ _context3.t0 = _context3["catch"](5);
839
+ console.log('Update user error', _context3.t0);
840
+ return _context3.abrupt("return", false);
854
841
  case 22:
855
842
  case "end":
856
- return _context4.stop();
843
+ return _context3.stop();
857
844
  }
858
- }, _callee4, null, [[5, 18]]);
845
+ }, _callee3, null, [[5, 18]]);
859
846
  }));
860
847
  return _setUpdateUserAction.apply(this, arguments);
861
848
  }
862
- function sendEmailVerificationAction(_x5) {
849
+ function sendEmailVerificationAction(_x4) {
863
850
  return _sendEmailVerificationAction.apply(this, arguments);
864
851
  }
865
852
  function _sendEmailVerificationAction() {
866
- _sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref5) {
853
+ _sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
867
854
  var dispatch, domainName, token, sendEmailFetch;
868
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
869
- while (1) switch (_context5.prev = _context5.next) {
855
+ return _regeneratorRuntime().wrap(function _callee4$(_context4) {
856
+ while (1) switch (_context4.prev = _context4.next) {
870
857
  case 0:
871
858
  dispatch = _ref5.dispatch, domainName = _ref5.domainName, token = _ref5.token;
872
859
  dispatch({
@@ -880,13 +867,13 @@ function _sendEmailVerificationAction() {
880
867
  message: 'Sending email verification...'
881
868
  }
882
869
  });
883
- _context5.prev = 3;
884
- _context5.next = 6;
870
+ _context4.prev = 3;
871
+ _context4.next = 6;
885
872
  return sendEmailVerificationAPI(domainName, token);
886
873
  case 6:
887
- sendEmailFetch = _context5.sent;
874
+ sendEmailFetch = _context4.sent;
888
875
  if (!(sendEmailFetch.response.status === 200)) {
889
- _context5.next = 12;
876
+ _context4.next = 13;
890
877
  break;
891
878
  }
892
879
  dispatch({
@@ -896,11 +883,12 @@ function _sendEmailVerificationAction() {
896
883
  message: sendEmailFetch.data.message
897
884
  }
898
885
  });
899
- return _context5.abrupt("return", dispatch({
886
+ dispatch({
900
887
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
901
888
  payload: false
902
- }));
903
- case 12:
889
+ });
890
+ return _context4.abrupt("return", true);
891
+ case 13:
904
892
  dispatch({
905
893
  type: SET_SEND_EMAIL_VERIFICATION_STATUS,
906
894
  payload: {
@@ -908,16 +896,17 @@ function _sendEmailVerificationAction() {
908
896
  message: sendEmailFetch.data.message
909
897
  }
910
898
  });
911
- return _context5.abrupt("return", dispatch({
899
+ dispatch({
912
900
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
913
901
  payload: false
914
- }));
915
- case 14:
916
- _context5.next = 20;
917
- break;
902
+ });
903
+ return _context4.abrupt("return", false);
918
904
  case 16:
919
- _context5.prev = 16;
920
- _context5.t0 = _context5["catch"](3);
905
+ _context4.next = 23;
906
+ break;
907
+ case 18:
908
+ _context4.prev = 18;
909
+ _context4.t0 = _context4["catch"](3);
921
910
  dispatch({
922
911
  type: SET_SEND_EMAIL_VERIFICATION_STATUS,
923
912
  payload: {
@@ -925,104 +914,105 @@ function _sendEmailVerificationAction() {
925
914
  message: 'Send email verification fetch error'
926
915
  }
927
916
  });
928
- return _context5.abrupt("return", dispatch({
917
+ dispatch({
929
918
  type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
930
919
  payload: false
931
- }));
932
- case 20:
920
+ });
921
+ return _context4.abrupt("return", false);
922
+ case 23:
933
923
  case "end":
934
- return _context5.stop();
924
+ return _context4.stop();
935
925
  }
936
- }, _callee5, null, [[3, 16]]);
926
+ }, _callee4, null, [[3, 18]]);
937
927
  }));
938
928
  return _sendEmailVerificationAction.apply(this, arguments);
939
929
  }
940
- function checkTokenAction(_x6) {
930
+ function checkTokenAction(_x5) {
941
931
  return _checkTokenAction.apply(this, arguments);
942
932
  }
943
933
  function _checkTokenAction() {
944
- _checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref6) {
934
+ _checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
945
935
  var dispatch, domainName, sid, token, refreshAccessTokenFetch;
946
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
947
- while (1) switch (_context6.prev = _context6.next) {
936
+ return _regeneratorRuntime().wrap(function _callee5$(_context5) {
937
+ while (1) switch (_context5.prev = _context5.next) {
948
938
  case 0:
949
939
  dispatch = _ref6.dispatch, domainName = _ref6.domainName, sid = _ref6.sid, token = _ref6.token;
950
- _context6.prev = 1;
951
- _context6.next = 4;
940
+ _context5.prev = 1;
941
+ _context5.next = 4;
952
942
  return refreshAccessTokenAPI(domainName, token);
953
943
  case 4:
954
- refreshAccessTokenFetch = _context6.sent;
944
+ refreshAccessTokenFetch = _context5.sent;
955
945
  if (!(refreshAccessTokenFetch.response.status === 200)) {
956
- _context6.next = 9;
946
+ _context5.next = 9;
957
947
  break;
958
948
  }
959
- return _context6.abrupt("return");
949
+ return _context5.abrupt("return");
960
950
  case 9:
961
951
  window.location.replace(getClientBasePath({
962
952
  domainName: domainName
963
953
  }) + "/" + routes.tenantSignin + "/" + sid);
964
- return _context6.abrupt("return", resetUser(dispatch));
954
+ return _context5.abrupt("return", resetUser(dispatch));
965
955
  case 11:
966
- _context6.next = 17;
956
+ _context5.next = 17;
967
957
  break;
968
958
  case 13:
969
- _context6.prev = 13;
970
- _context6.t0 = _context6["catch"](1);
959
+ _context5.prev = 13;
960
+ _context5.t0 = _context5["catch"](1);
971
961
  resetUser(dispatch);
972
- throw _context6.t0;
962
+ throw _context5.t0;
973
963
  case 17:
974
964
  case "end":
975
- return _context6.stop();
965
+ return _context5.stop();
976
966
  }
977
- }, _callee6, null, [[1, 13]]);
967
+ }, _callee5, null, [[1, 13]]);
978
968
  }));
979
969
  return _checkTokenAction.apply(this, arguments);
980
970
  }
981
- function getAccessTokenAction(_x7) {
971
+ function getAccessTokenAction(_x6) {
982
972
  return _getAccessTokenAction.apply(this, arguments);
983
973
  }
984
974
  ///////////////////////////////////////////
985
975
  //////////////////////////////////////////
986
976
  function _getAccessTokenAction() {
987
- _getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7(_ref7) {
977
+ _getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref7) {
988
978
  var dispatch, domainName, token_ls, refreshAccessTokenFetch, _refreshAccessTokenFe;
989
- return _regeneratorRuntime().wrap(function _callee7$(_context7) {
990
- while (1) switch (_context7.prev = _context7.next) {
979
+ return _regeneratorRuntime().wrap(function _callee6$(_context6) {
980
+ while (1) switch (_context6.prev = _context6.next) {
991
981
  case 0:
992
982
  dispatch = _ref7.dispatch, domainName = _ref7.domainName;
993
983
  token_ls = localStorage.getItem(TOKEN_LS);
994
984
  if (token_ls) {
995
- _context7.next = 4;
985
+ _context6.next = 4;
996
986
  break;
997
987
  }
998
- return _context7.abrupt("return");
988
+ return _context6.abrupt("return");
999
989
  case 4:
1000
- _context7.prev = 4;
1001
- _context7.next = 7;
990
+ _context6.prev = 4;
991
+ _context6.next = 7;
1002
992
  return refreshAccessTokenAPI(domainName, token_ls);
1003
993
  case 7:
1004
- refreshAccessTokenFetch = _context7.sent;
994
+ refreshAccessTokenFetch = _context6.sent;
1005
995
  if (!(refreshAccessTokenFetch.response.status === 200)) {
1006
- _context7.next = 12;
996
+ _context6.next = 12;
1007
997
  break;
1008
998
  }
1009
- return _context7.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
999
+ return _context6.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
1010
1000
  case 12:
1011
1001
  resetUser(dispatch);
1012
- return _context7.abrupt("return", 'token-not-found');
1002
+ return _context6.abrupt("return", 'token-not-found');
1013
1003
  case 14:
1014
- _context7.next = 20;
1004
+ _context6.next = 20;
1015
1005
  break;
1016
1006
  case 16:
1017
- _context7.prev = 16;
1018
- _context7.t0 = _context7["catch"](4);
1007
+ _context6.prev = 16;
1008
+ _context6.t0 = _context6["catch"](4);
1019
1009
  resetUser(dispatch);
1020
- throw _context7.t0;
1010
+ throw _context6.t0;
1021
1011
  case 20:
1022
1012
  case "end":
1023
- return _context7.stop();
1013
+ return _context6.stop();
1024
1014
  }
1025
- }, _callee7, null, [[4, 16]]);
1015
+ }, _callee6, null, [[4, 16]]);
1026
1016
  }));
1027
1017
  return _getAccessTokenAction.apply(this, arguments);
1028
1018
  }
@@ -1098,7 +1088,7 @@ var DauthProvider = function DauthProvider(props) {
1098
1088
  dispatch: dispatch
1099
1089
  });
1100
1090
  }, []);
1101
- var _getAccessToken = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1091
+ var getAccessToken = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
1102
1092
  var token;
1103
1093
  return _regeneratorRuntime().wrap(function _callee$(_context) {
1104
1094
  while (1) switch (_context.prev = _context.next) {
@@ -1158,29 +1148,44 @@ var DauthProvider = function DauthProvider(props) {
1158
1148
  if (!token_ls) return;
1159
1149
  return window.location.replace(getClientBasePath({
1160
1150
  domainName: domainName
1161
- }) + "\n /" + routes.tenantUpdateUser + "\n /" + sid + "\n /" + token_ls);
1151
+ }) + "/" + routes.tenantUpdateUser + "/" + sid + "/" + token_ls);
1162
1152
  }, [domainName, sid]);
1163
- var sendEmailVerification = React.useCallback(function () {
1164
- var token_ls = localStorage.getItem(TOKEN_LS);
1165
- if (!token_ls) return;
1166
- return sendEmailVerificationAction({
1167
- dispatch: dispatch,
1168
- domainName: domainName,
1169
- token: token_ls
1170
- });
1171
- }, [domainName]);
1153
+ var sendEmailVerification = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
1154
+ var token_ls;
1155
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1156
+ while (1) switch (_context3.prev = _context3.next) {
1157
+ case 0:
1158
+ token_ls = localStorage.getItem(TOKEN_LS);
1159
+ if (token_ls) {
1160
+ _context3.next = 3;
1161
+ break;
1162
+ }
1163
+ return _context3.abrupt("return", false);
1164
+ case 3:
1165
+ _context3.next = 5;
1166
+ return sendEmailVerificationAction({
1167
+ dispatch: dispatch,
1168
+ domainName: domainName,
1169
+ token: token_ls
1170
+ });
1171
+ case 5:
1172
+ return _context3.abrupt("return", _context3.sent);
1173
+ case 6:
1174
+ case "end":
1175
+ return _context3.stop();
1176
+ }
1177
+ }, _callee3);
1178
+ })), [domainName]);
1172
1179
  var memoProvider = React.useMemo(function () {
1173
1180
  return _extends({}, dauthState, {
1174
1181
  loginWithRedirect: loginWithRedirect,
1175
1182
  logout: logout,
1176
- getAccessToken: function getAccessToken() {
1177
- return _getAccessToken() || '';
1178
- },
1183
+ getAccessToken: getAccessToken,
1179
1184
  updateUser: updateUser,
1180
1185
  updateUserWithRedirect: updateUserWithRedirect,
1181
1186
  sendEmailVerification: sendEmailVerification
1182
1187
  });
1183
- }, [dauthState, loginWithRedirect, logout, _getAccessToken, updateUser, updateUserWithRedirect, sendEmailVerification]);
1188
+ }, [dauthState, loginWithRedirect, logout, getAccessToken, updateUser, updateUserWithRedirect, sendEmailVerification]);
1184
1189
  return React__default.createElement(DauthContext.Provider, {
1185
1190
  value: memoProvider
1186
1191
  }, children);