dauth-context-react 0.2.100 → 0.2.101

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