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.
- package/dist/dauth-context-react.cjs.development.js +137 -132
- package/dist/dauth-context-react.cjs.development.js.map +1 -1
- package/dist/dauth-context-react.cjs.production.min.js +1 -1
- package/dist/dauth-context-react.cjs.production.min.js.map +1 -1
- package/dist/dauth-context-react.esm.js +137 -132
- package/dist/dauth-context-react.esm.js.map +1 -1
- package/dist/initialDauthState.d.ts +1 -1
- package/dist/reducer/dauth.actions.d.ts +2 -2
- package/package.json +1 -1
- package/src/index.tsx +8 -9
- package/src/initialDauthState.ts +2 -2
- package/src/reducer/dauth.actions.ts +7 -4
|
@@ -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';
|
|
@@ -762,111 +764,96 @@ function _setAutoLoginAction() {
|
|
|
762
764
|
}));
|
|
763
765
|
return _setAutoLoginAction.apply(this, arguments);
|
|
764
766
|
}
|
|
765
|
-
function setLogoutAction(
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
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(
|
|
793
|
+
function setUpdateUserAction(_x3) {
|
|
807
794
|
return _setUpdateUserAction.apply(this, arguments);
|
|
808
795
|
}
|
|
809
796
|
function _setUpdateUserAction() {
|
|
810
|
-
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
797
|
+
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
811
798
|
var dispatch, domainName, user, token, getUserFetch;
|
|
812
|
-
return _regeneratorRuntime().wrap(function
|
|
813
|
-
while (1) switch (
|
|
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
|
-
|
|
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
|
|
814
|
+
return _context3.abrupt("return", false);
|
|
828
815
|
case 5:
|
|
829
|
-
|
|
830
|
-
|
|
816
|
+
_context3.prev = 5;
|
|
817
|
+
_context3.next = 8;
|
|
831
818
|
return updateUserAPI(domainName, user, token);
|
|
832
819
|
case 8:
|
|
833
|
-
getUserFetch =
|
|
820
|
+
getUserFetch = _context3.sent;
|
|
834
821
|
if (!(getUserFetch.response.status === 200)) {
|
|
835
|
-
|
|
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
|
|
829
|
+
return _context3.abrupt("return", true);
|
|
843
830
|
case 14:
|
|
844
831
|
console.log('Update user error', getUserFetch.data.message);
|
|
845
|
-
return
|
|
832
|
+
return _context3.abrupt("return", false);
|
|
846
833
|
case 16:
|
|
847
|
-
|
|
834
|
+
_context3.next = 22;
|
|
848
835
|
break;
|
|
849
836
|
case 18:
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
console.log('Update user error',
|
|
853
|
-
return
|
|
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
|
|
843
|
+
return _context3.stop();
|
|
857
844
|
}
|
|
858
|
-
},
|
|
845
|
+
}, _callee3, null, [[5, 18]]);
|
|
859
846
|
}));
|
|
860
847
|
return _setUpdateUserAction.apply(this, arguments);
|
|
861
848
|
}
|
|
862
|
-
function sendEmailVerificationAction(
|
|
849
|
+
function sendEmailVerificationAction(_x4) {
|
|
863
850
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
864
851
|
}
|
|
865
852
|
function _sendEmailVerificationAction() {
|
|
866
|
-
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
853
|
+
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
|
|
867
854
|
var dispatch, domainName, token, sendEmailFetch;
|
|
868
|
-
return _regeneratorRuntime().wrap(function
|
|
869
|
-
while (1) switch (
|
|
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
|
-
|
|
884
|
-
|
|
870
|
+
_context4.prev = 3;
|
|
871
|
+
_context4.next = 6;
|
|
885
872
|
return sendEmailVerificationAPI(domainName, token);
|
|
886
873
|
case 6:
|
|
887
|
-
sendEmailFetch =
|
|
874
|
+
sendEmailFetch = _context4.sent;
|
|
888
875
|
if (!(sendEmailFetch.response.status === 200)) {
|
|
889
|
-
|
|
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
|
-
|
|
886
|
+
dispatch({
|
|
900
887
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
901
888
|
payload: false
|
|
902
|
-
})
|
|
903
|
-
|
|
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
|
-
|
|
899
|
+
dispatch({
|
|
912
900
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
913
901
|
payload: false
|
|
914
|
-
})
|
|
915
|
-
|
|
916
|
-
_context5.next = 20;
|
|
917
|
-
break;
|
|
902
|
+
});
|
|
903
|
+
return _context4.abrupt("return", false);
|
|
918
904
|
case 16:
|
|
919
|
-
|
|
920
|
-
|
|
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
|
-
|
|
917
|
+
dispatch({
|
|
929
918
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
930
919
|
payload: false
|
|
931
|
-
})
|
|
932
|
-
|
|
920
|
+
});
|
|
921
|
+
return _context4.abrupt("return", false);
|
|
922
|
+
case 23:
|
|
933
923
|
case "end":
|
|
934
|
-
return
|
|
924
|
+
return _context4.stop();
|
|
935
925
|
}
|
|
936
|
-
},
|
|
926
|
+
}, _callee4, null, [[3, 18]]);
|
|
937
927
|
}));
|
|
938
928
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
939
929
|
}
|
|
940
|
-
function checkTokenAction(
|
|
930
|
+
function checkTokenAction(_x5) {
|
|
941
931
|
return _checkTokenAction.apply(this, arguments);
|
|
942
932
|
}
|
|
943
933
|
function _checkTokenAction() {
|
|
944
|
-
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
934
|
+
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
945
935
|
var dispatch, domainName, sid, token, refreshAccessTokenFetch;
|
|
946
|
-
return _regeneratorRuntime().wrap(function
|
|
947
|
-
while (1) switch (
|
|
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
|
-
|
|
951
|
-
|
|
940
|
+
_context5.prev = 1;
|
|
941
|
+
_context5.next = 4;
|
|
952
942
|
return refreshAccessTokenAPI(domainName, token);
|
|
953
943
|
case 4:
|
|
954
|
-
refreshAccessTokenFetch =
|
|
944
|
+
refreshAccessTokenFetch = _context5.sent;
|
|
955
945
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
956
|
-
|
|
946
|
+
_context5.next = 9;
|
|
957
947
|
break;
|
|
958
948
|
}
|
|
959
|
-
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
|
|
954
|
+
return _context5.abrupt("return", resetUser(dispatch));
|
|
965
955
|
case 11:
|
|
966
|
-
|
|
956
|
+
_context5.next = 17;
|
|
967
957
|
break;
|
|
968
958
|
case 13:
|
|
969
|
-
|
|
970
|
-
|
|
959
|
+
_context5.prev = 13;
|
|
960
|
+
_context5.t0 = _context5["catch"](1);
|
|
971
961
|
resetUser(dispatch);
|
|
972
|
-
throw
|
|
962
|
+
throw _context5.t0;
|
|
973
963
|
case 17:
|
|
974
964
|
case "end":
|
|
975
|
-
return
|
|
965
|
+
return _context5.stop();
|
|
976
966
|
}
|
|
977
|
-
},
|
|
967
|
+
}, _callee5, null, [[1, 13]]);
|
|
978
968
|
}));
|
|
979
969
|
return _checkTokenAction.apply(this, arguments);
|
|
980
970
|
}
|
|
981
|
-
function getAccessTokenAction(
|
|
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
|
|
977
|
+
_getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref7) {
|
|
988
978
|
var dispatch, domainName, token_ls, refreshAccessTokenFetch, _refreshAccessTokenFe;
|
|
989
|
-
return _regeneratorRuntime().wrap(function
|
|
990
|
-
while (1) switch (
|
|
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
|
-
|
|
985
|
+
_context6.next = 4;
|
|
996
986
|
break;
|
|
997
987
|
}
|
|
998
|
-
return
|
|
988
|
+
return _context6.abrupt("return");
|
|
999
989
|
case 4:
|
|
1000
|
-
|
|
1001
|
-
|
|
990
|
+
_context6.prev = 4;
|
|
991
|
+
_context6.next = 7;
|
|
1002
992
|
return refreshAccessTokenAPI(domainName, token_ls);
|
|
1003
993
|
case 7:
|
|
1004
|
-
refreshAccessTokenFetch =
|
|
994
|
+
refreshAccessTokenFetch = _context6.sent;
|
|
1005
995
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
1006
|
-
|
|
996
|
+
_context6.next = 12;
|
|
1007
997
|
break;
|
|
1008
998
|
}
|
|
1009
|
-
return
|
|
999
|
+
return _context6.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
|
|
1010
1000
|
case 12:
|
|
1011
1001
|
resetUser(dispatch);
|
|
1012
|
-
return
|
|
1002
|
+
return _context6.abrupt("return", 'token-not-found');
|
|
1013
1003
|
case 14:
|
|
1014
|
-
|
|
1004
|
+
_context6.next = 20;
|
|
1015
1005
|
break;
|
|
1016
1006
|
case 16:
|
|
1017
|
-
|
|
1018
|
-
|
|
1007
|
+
_context6.prev = 16;
|
|
1008
|
+
_context6.t0 = _context6["catch"](4);
|
|
1019
1009
|
resetUser(dispatch);
|
|
1020
|
-
throw
|
|
1010
|
+
throw _context6.t0;
|
|
1021
1011
|
case 20:
|
|
1022
1012
|
case "end":
|
|
1023
|
-
return
|
|
1013
|
+
return _context6.stop();
|
|
1024
1014
|
}
|
|
1025
|
-
},
|
|
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
|
|
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
|
-
}) + "
|
|
1151
|
+
}) + "/" + routes.tenantUpdateUser + "/" + sid + "/" + token_ls);
|
|
1162
1152
|
}, [domainName, sid]);
|
|
1163
|
-
var sendEmailVerification = React.useCallback(function () {
|
|
1164
|
-
var token_ls
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
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:
|
|
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,
|
|
1188
|
+
}, [dauthState, loginWithRedirect, logout, getAccessToken, updateUser, updateUserWithRedirect, sendEmailVerification]);
|
|
1184
1189
|
return React__default.createElement(DauthContext.Provider, {
|
|
1185
1190
|
value: memoProvider
|
|
1186
1191
|
}, children);
|