dauth-context-react 0.2.1 → 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/constants.d.ts +1 -1
- package/dist/dauth-context-react.cjs.development.js +200 -179
- 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 +200 -179
- package/dist/dauth-context-react.esm.js.map +1 -1
- package/dist/initialDauthState.d.ts +3 -3
- package/dist/reducer/dauth.actions.d.ts +5 -5
- package/package.json +1 -1
- package/src/constants.ts +1 -1
- package/src/index.tsx +21 -22
- package/src/initialDauthState.ts +6 -6
- package/src/reducer/dauth.actions.ts +22 -16
|
@@ -356,9 +356,11 @@ var initialDauthState = {
|
|
|
356
356
|
loginWithRedirect: function loginWithRedirect() {},
|
|
357
357
|
logout: function logout() {},
|
|
358
358
|
getAccessToken: function getAccessToken() {
|
|
359
|
-
return
|
|
359
|
+
return Promise.resolve('');
|
|
360
|
+
},
|
|
361
|
+
updateUser: function updateUser() {
|
|
362
|
+
return Promise.resolve(false);
|
|
360
363
|
},
|
|
361
|
-
updateUser: function updateUser() {},
|
|
362
364
|
updateUserWithRedirect: function updateUserWithRedirect() {},
|
|
363
365
|
// Send email verification
|
|
364
366
|
sendEmailVerificationStatus: {
|
|
@@ -368,7 +370,9 @@ var initialDauthState = {
|
|
|
368
370
|
},
|
|
369
371
|
isLoading: false
|
|
370
372
|
},
|
|
371
|
-
sendEmailVerification: function sendEmailVerification() {
|
|
373
|
+
sendEmailVerification: function sendEmailVerification() {
|
|
374
|
+
return Promise.resolve(false);
|
|
375
|
+
}
|
|
372
376
|
};
|
|
373
377
|
|
|
374
378
|
var LOGIN = 'LOGIN';
|
|
@@ -608,18 +612,18 @@ var refreshAccessTokenAPI = /*#__PURE__*/function () {
|
|
|
608
612
|
};
|
|
609
613
|
}();
|
|
610
614
|
|
|
611
|
-
var
|
|
615
|
+
var TOKEN_LS = 'dauth_state';
|
|
612
616
|
|
|
613
617
|
function setDauthStateAction(_x) {
|
|
614
618
|
return _setDauthStateAction.apply(this, arguments);
|
|
615
619
|
}
|
|
616
620
|
function _setDauthStateAction() {
|
|
617
621
|
_setDauthStateAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
618
|
-
var dispatch,
|
|
622
|
+
var dispatch, token, domainName, getUserFetch;
|
|
619
623
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
620
624
|
while (1) switch (_context.prev = _context.next) {
|
|
621
625
|
case 0:
|
|
622
|
-
dispatch = _ref.dispatch,
|
|
626
|
+
dispatch = _ref.dispatch, token = _ref.token, domainName = _ref.domainName;
|
|
623
627
|
dispatch({
|
|
624
628
|
type: SET_IS_LOADING,
|
|
625
629
|
payload: {
|
|
@@ -628,7 +632,7 @@ function _setDauthStateAction() {
|
|
|
628
632
|
});
|
|
629
633
|
_context.prev = 2;
|
|
630
634
|
_context.next = 5;
|
|
631
|
-
return getUserAPI(domainName,
|
|
635
|
+
return getUserAPI(domainName, token);
|
|
632
636
|
case 5:
|
|
633
637
|
getUserFetch = _context.sent;
|
|
634
638
|
if (!(getUserFetch.response.status === 200)) {
|
|
@@ -644,7 +648,7 @@ function _setDauthStateAction() {
|
|
|
644
648
|
}
|
|
645
649
|
});
|
|
646
650
|
window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);
|
|
647
|
-
return _context.abrupt("return", localStorage.setItem(
|
|
651
|
+
return _context.abrupt("return", localStorage.setItem(TOKEN_LS, token));
|
|
648
652
|
case 12:
|
|
649
653
|
return _context.abrupt("return", resetUser(dispatch));
|
|
650
654
|
case 13:
|
|
@@ -713,7 +717,7 @@ function _setAutoLoginAction() {
|
|
|
713
717
|
isAuthenticated: true
|
|
714
718
|
}
|
|
715
719
|
});
|
|
716
|
-
localStorage.setItem(
|
|
720
|
+
localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
|
|
717
721
|
return _context2.abrupt("return");
|
|
718
722
|
case 16:
|
|
719
723
|
window.location.replace(getClientBasePath({
|
|
@@ -753,108 +757,96 @@ function _setAutoLoginAction() {
|
|
|
753
757
|
}));
|
|
754
758
|
return _setAutoLoginAction.apply(this, arguments);
|
|
755
759
|
}
|
|
756
|
-
function setLogoutAction(
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
});
|
|
782
|
-
localStorage.removeItem(DAUTH_STATE);
|
|
783
|
-
return _context3.abrupt("return", dispatch({
|
|
784
|
-
type: SET_IS_LOADING,
|
|
785
|
-
payload: {
|
|
786
|
-
isLoading: false
|
|
787
|
-
}
|
|
788
|
-
}));
|
|
789
|
-
case 5:
|
|
790
|
-
case "end":
|
|
791
|
-
return _context3.stop();
|
|
792
|
-
}
|
|
793
|
-
}, _callee3);
|
|
794
|
-
}));
|
|
795
|
-
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
|
+
});
|
|
796
785
|
}
|
|
797
|
-
function setUpdateUserAction(
|
|
786
|
+
function setUpdateUserAction(_x3) {
|
|
798
787
|
return _setUpdateUserAction.apply(this, arguments);
|
|
799
788
|
}
|
|
800
789
|
function _setUpdateUserAction() {
|
|
801
|
-
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
790
|
+
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
802
791
|
var dispatch, domainName, user, token, getUserFetch;
|
|
803
|
-
return _regeneratorRuntime().wrap(function
|
|
804
|
-
while (1) switch (
|
|
792
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
793
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
805
794
|
case 0:
|
|
806
795
|
dispatch = _ref4.dispatch, domainName = _ref4.domainName, user = _ref4.user, token = _ref4.token;
|
|
807
796
|
if (user.language) {
|
|
808
797
|
window.document.documentElement.setAttribute('lang', user.language);
|
|
809
798
|
}
|
|
810
799
|
if (token) {
|
|
811
|
-
|
|
800
|
+
_context3.next = 5;
|
|
812
801
|
break;
|
|
813
802
|
}
|
|
814
|
-
|
|
803
|
+
dispatch({
|
|
815
804
|
type: UPDATE_USER,
|
|
816
805
|
payload: user
|
|
817
|
-
})
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
806
|
+
});
|
|
807
|
+
return _context3.abrupt("return", false);
|
|
808
|
+
case 5:
|
|
809
|
+
_context3.prev = 5;
|
|
810
|
+
_context3.next = 8;
|
|
821
811
|
return updateUserAPI(domainName, user, token);
|
|
822
|
-
case
|
|
823
|
-
getUserFetch =
|
|
812
|
+
case 8:
|
|
813
|
+
getUserFetch = _context3.sent;
|
|
824
814
|
if (!(getUserFetch.response.status === 200)) {
|
|
825
|
-
|
|
815
|
+
_context3.next = 14;
|
|
826
816
|
break;
|
|
827
817
|
}
|
|
828
|
-
|
|
818
|
+
dispatch({
|
|
829
819
|
type: UPDATE_USER,
|
|
830
820
|
payload: getUserFetch.data.user
|
|
831
|
-
})
|
|
832
|
-
|
|
833
|
-
console.log('Update user error', getUserFetch.data.message);
|
|
834
|
-
return _context4.abrupt("return");
|
|
821
|
+
});
|
|
822
|
+
return _context3.abrupt("return", true);
|
|
835
823
|
case 14:
|
|
836
|
-
|
|
837
|
-
|
|
824
|
+
console.log('Update user error', getUserFetch.data.message);
|
|
825
|
+
return _context3.abrupt("return", false);
|
|
838
826
|
case 16:
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
827
|
+
_context3.next = 22;
|
|
828
|
+
break;
|
|
829
|
+
case 18:
|
|
830
|
+
_context3.prev = 18;
|
|
831
|
+
_context3.t0 = _context3["catch"](5);
|
|
832
|
+
console.log('Update user error', _context3.t0);
|
|
833
|
+
return _context3.abrupt("return", false);
|
|
834
|
+
case 22:
|
|
843
835
|
case "end":
|
|
844
|
-
return
|
|
836
|
+
return _context3.stop();
|
|
845
837
|
}
|
|
846
|
-
},
|
|
838
|
+
}, _callee3, null, [[5, 18]]);
|
|
847
839
|
}));
|
|
848
840
|
return _setUpdateUserAction.apply(this, arguments);
|
|
849
841
|
}
|
|
850
|
-
function sendEmailVerificationAction(
|
|
842
|
+
function sendEmailVerificationAction(_x4) {
|
|
851
843
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
852
844
|
}
|
|
853
845
|
function _sendEmailVerificationAction() {
|
|
854
|
-
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
846
|
+
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
|
|
855
847
|
var dispatch, domainName, token, sendEmailFetch;
|
|
856
|
-
return _regeneratorRuntime().wrap(function
|
|
857
|
-
while (1) switch (
|
|
848
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
849
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
858
850
|
case 0:
|
|
859
851
|
dispatch = _ref5.dispatch, domainName = _ref5.domainName, token = _ref5.token;
|
|
860
852
|
dispatch({
|
|
@@ -868,13 +860,13 @@ function _sendEmailVerificationAction() {
|
|
|
868
860
|
message: 'Sending email verification...'
|
|
869
861
|
}
|
|
870
862
|
});
|
|
871
|
-
|
|
872
|
-
|
|
863
|
+
_context4.prev = 3;
|
|
864
|
+
_context4.next = 6;
|
|
873
865
|
return sendEmailVerificationAPI(domainName, token);
|
|
874
866
|
case 6:
|
|
875
|
-
sendEmailFetch =
|
|
867
|
+
sendEmailFetch = _context4.sent;
|
|
876
868
|
if (!(sendEmailFetch.response.status === 200)) {
|
|
877
|
-
|
|
869
|
+
_context4.next = 13;
|
|
878
870
|
break;
|
|
879
871
|
}
|
|
880
872
|
dispatch({
|
|
@@ -884,11 +876,12 @@ function _sendEmailVerificationAction() {
|
|
|
884
876
|
message: sendEmailFetch.data.message
|
|
885
877
|
}
|
|
886
878
|
});
|
|
887
|
-
|
|
879
|
+
dispatch({
|
|
888
880
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
889
881
|
payload: false
|
|
890
|
-
})
|
|
891
|
-
|
|
882
|
+
});
|
|
883
|
+
return _context4.abrupt("return", true);
|
|
884
|
+
case 13:
|
|
892
885
|
dispatch({
|
|
893
886
|
type: SET_SEND_EMAIL_VERIFICATION_STATUS,
|
|
894
887
|
payload: {
|
|
@@ -896,16 +889,17 @@ function _sendEmailVerificationAction() {
|
|
|
896
889
|
message: sendEmailFetch.data.message
|
|
897
890
|
}
|
|
898
891
|
});
|
|
899
|
-
|
|
892
|
+
dispatch({
|
|
900
893
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
901
894
|
payload: false
|
|
902
|
-
})
|
|
903
|
-
|
|
904
|
-
_context5.next = 20;
|
|
905
|
-
break;
|
|
895
|
+
});
|
|
896
|
+
return _context4.abrupt("return", false);
|
|
906
897
|
case 16:
|
|
907
|
-
|
|
908
|
-
|
|
898
|
+
_context4.next = 23;
|
|
899
|
+
break;
|
|
900
|
+
case 18:
|
|
901
|
+
_context4.prev = 18;
|
|
902
|
+
_context4.t0 = _context4["catch"](3);
|
|
909
903
|
dispatch({
|
|
910
904
|
type: SET_SEND_EMAIL_VERIFICATION_STATUS,
|
|
911
905
|
payload: {
|
|
@@ -913,109 +907,110 @@ function _sendEmailVerificationAction() {
|
|
|
913
907
|
message: 'Send email verification fetch error'
|
|
914
908
|
}
|
|
915
909
|
});
|
|
916
|
-
|
|
910
|
+
dispatch({
|
|
917
911
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
918
912
|
payload: false
|
|
919
|
-
})
|
|
920
|
-
|
|
913
|
+
});
|
|
914
|
+
return _context4.abrupt("return", false);
|
|
915
|
+
case 23:
|
|
921
916
|
case "end":
|
|
922
|
-
return
|
|
917
|
+
return _context4.stop();
|
|
923
918
|
}
|
|
924
|
-
},
|
|
919
|
+
}, _callee4, null, [[3, 18]]);
|
|
925
920
|
}));
|
|
926
921
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
927
922
|
}
|
|
928
|
-
function checkTokenAction(
|
|
923
|
+
function checkTokenAction(_x5) {
|
|
929
924
|
return _checkTokenAction.apply(this, arguments);
|
|
930
925
|
}
|
|
931
926
|
function _checkTokenAction() {
|
|
932
|
-
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
927
|
+
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
933
928
|
var dispatch, domainName, sid, token, refreshAccessTokenFetch;
|
|
934
|
-
return _regeneratorRuntime().wrap(function
|
|
935
|
-
while (1) switch (
|
|
929
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
930
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
936
931
|
case 0:
|
|
937
932
|
dispatch = _ref6.dispatch, domainName = _ref6.domainName, sid = _ref6.sid, token = _ref6.token;
|
|
938
|
-
|
|
939
|
-
|
|
933
|
+
_context5.prev = 1;
|
|
934
|
+
_context5.next = 4;
|
|
940
935
|
return refreshAccessTokenAPI(domainName, token);
|
|
941
936
|
case 4:
|
|
942
|
-
refreshAccessTokenFetch =
|
|
937
|
+
refreshAccessTokenFetch = _context5.sent;
|
|
943
938
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
944
|
-
|
|
939
|
+
_context5.next = 9;
|
|
945
940
|
break;
|
|
946
941
|
}
|
|
947
|
-
return
|
|
942
|
+
return _context5.abrupt("return");
|
|
948
943
|
case 9:
|
|
949
944
|
window.location.replace(getClientBasePath({
|
|
950
945
|
domainName: domainName
|
|
951
946
|
}) + "/" + routes.tenantSignin + "/" + sid);
|
|
952
|
-
return
|
|
947
|
+
return _context5.abrupt("return", resetUser(dispatch));
|
|
953
948
|
case 11:
|
|
954
|
-
|
|
949
|
+
_context5.next = 17;
|
|
955
950
|
break;
|
|
956
951
|
case 13:
|
|
957
|
-
|
|
958
|
-
|
|
952
|
+
_context5.prev = 13;
|
|
953
|
+
_context5.t0 = _context5["catch"](1);
|
|
959
954
|
resetUser(dispatch);
|
|
960
|
-
throw
|
|
955
|
+
throw _context5.t0;
|
|
961
956
|
case 17:
|
|
962
957
|
case "end":
|
|
963
|
-
return
|
|
958
|
+
return _context5.stop();
|
|
964
959
|
}
|
|
965
|
-
},
|
|
960
|
+
}, _callee5, null, [[1, 13]]);
|
|
966
961
|
}));
|
|
967
962
|
return _checkTokenAction.apply(this, arguments);
|
|
968
963
|
}
|
|
969
|
-
function getAccessTokenAction(
|
|
964
|
+
function getAccessTokenAction(_x6) {
|
|
970
965
|
return _getAccessTokenAction.apply(this, arguments);
|
|
971
966
|
}
|
|
972
967
|
///////////////////////////////////////////
|
|
973
968
|
//////////////////////////////////////////
|
|
974
969
|
function _getAccessTokenAction() {
|
|
975
|
-
_getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
970
|
+
_getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref7) {
|
|
976
971
|
var dispatch, domainName, token_ls, refreshAccessTokenFetch, _refreshAccessTokenFe;
|
|
977
|
-
return _regeneratorRuntime().wrap(function
|
|
978
|
-
while (1) switch (
|
|
972
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
973
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
979
974
|
case 0:
|
|
980
975
|
dispatch = _ref7.dispatch, domainName = _ref7.domainName;
|
|
981
|
-
token_ls = localStorage.getItem(
|
|
976
|
+
token_ls = localStorage.getItem(TOKEN_LS);
|
|
982
977
|
if (token_ls) {
|
|
983
|
-
|
|
978
|
+
_context6.next = 4;
|
|
984
979
|
break;
|
|
985
980
|
}
|
|
986
|
-
return
|
|
981
|
+
return _context6.abrupt("return");
|
|
987
982
|
case 4:
|
|
988
|
-
|
|
989
|
-
|
|
983
|
+
_context6.prev = 4;
|
|
984
|
+
_context6.next = 7;
|
|
990
985
|
return refreshAccessTokenAPI(domainName, token_ls);
|
|
991
986
|
case 7:
|
|
992
|
-
refreshAccessTokenFetch =
|
|
987
|
+
refreshAccessTokenFetch = _context6.sent;
|
|
993
988
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
994
|
-
|
|
989
|
+
_context6.next = 12;
|
|
995
990
|
break;
|
|
996
991
|
}
|
|
997
|
-
return
|
|
992
|
+
return _context6.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
|
|
998
993
|
case 12:
|
|
999
994
|
resetUser(dispatch);
|
|
1000
|
-
return
|
|
995
|
+
return _context6.abrupt("return", 'token-not-found');
|
|
1001
996
|
case 14:
|
|
1002
|
-
|
|
997
|
+
_context6.next = 20;
|
|
1003
998
|
break;
|
|
1004
999
|
case 16:
|
|
1005
|
-
|
|
1006
|
-
|
|
1000
|
+
_context6.prev = 16;
|
|
1001
|
+
_context6.t0 = _context6["catch"](4);
|
|
1007
1002
|
resetUser(dispatch);
|
|
1008
|
-
throw
|
|
1003
|
+
throw _context6.t0;
|
|
1009
1004
|
case 20:
|
|
1010
1005
|
case "end":
|
|
1011
|
-
return
|
|
1006
|
+
return _context6.stop();
|
|
1012
1007
|
}
|
|
1013
|
-
},
|
|
1008
|
+
}, _callee6, null, [[4, 16]]);
|
|
1014
1009
|
}));
|
|
1015
1010
|
return _getAccessTokenAction.apply(this, arguments);
|
|
1016
1011
|
}
|
|
1017
1012
|
var resetUser = function resetUser(dispatch) {
|
|
1018
|
-
localStorage.removeItem(
|
|
1013
|
+
localStorage.removeItem(TOKEN_LS);
|
|
1019
1014
|
return dispatch({
|
|
1020
1015
|
type: LOGIN,
|
|
1021
1016
|
payload: {
|
|
@@ -1037,7 +1032,7 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1037
1032
|
useEffect(function () {
|
|
1038
1033
|
if (!dauthState.isAuthenticated) return;
|
|
1039
1034
|
var interval = setInterval(function () {
|
|
1040
|
-
var token_ls = localStorage.getItem(
|
|
1035
|
+
var token_ls = localStorage.getItem(TOKEN_LS);
|
|
1041
1036
|
if (!token_ls) return;
|
|
1042
1037
|
checkTokenAction({
|
|
1043
1038
|
dispatch: dispatch,
|
|
@@ -1055,18 +1050,18 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1055
1050
|
var queryString = window.location.search;
|
|
1056
1051
|
if (!queryString) return;
|
|
1057
1052
|
var urlParams = new URLSearchParams(queryString);
|
|
1058
|
-
var
|
|
1059
|
-
if (
|
|
1053
|
+
var token_url = urlParams.get(TOKEN_LS);
|
|
1054
|
+
if (token_url && !dauthState.isAuthenticated) {
|
|
1060
1055
|
setDauthStateAction({
|
|
1061
1056
|
dispatch: dispatch,
|
|
1062
|
-
|
|
1057
|
+
token: token_url,
|
|
1063
1058
|
domainName: domainName
|
|
1064
1059
|
});
|
|
1065
1060
|
}
|
|
1066
1061
|
}, []);
|
|
1067
1062
|
// Auto Login
|
|
1068
1063
|
useEffect(function () {
|
|
1069
|
-
var dauth_state_ls = localStorage.getItem(
|
|
1064
|
+
var dauth_state_ls = localStorage.getItem(TOKEN_LS);
|
|
1070
1065
|
if (dauth_state_ls && !dauthState.isAuthenticated) {
|
|
1071
1066
|
setAutoLoginAction({
|
|
1072
1067
|
dispatch: dispatch,
|
|
@@ -1086,7 +1081,7 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1086
1081
|
dispatch: dispatch
|
|
1087
1082
|
});
|
|
1088
1083
|
}, []);
|
|
1089
|
-
var
|
|
1084
|
+
var getAccessToken = useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1090
1085
|
var token;
|
|
1091
1086
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1092
1087
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -1105,59 +1100,85 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1105
1100
|
}
|
|
1106
1101
|
}, _callee);
|
|
1107
1102
|
})), []);
|
|
1108
|
-
var updateUser = useCallback(function (
|
|
1109
|
-
var
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1103
|
+
var updateUser = useCallback( /*#__PURE__*/function () {
|
|
1104
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
1105
|
+
var name, lastname, nickname, tel_prefix, tel_suffix, language, avatar, token_ls, user;
|
|
1106
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1107
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1108
|
+
case 0:
|
|
1109
|
+
name = _ref2.name, lastname = _ref2.lastname, nickname = _ref2.nickname, tel_prefix = _ref2.tel_prefix, tel_suffix = _ref2.tel_suffix, language = _ref2.language, avatar = _ref2.avatar;
|
|
1110
|
+
token_ls = localStorage.getItem(TOKEN_LS);
|
|
1111
|
+
user = {
|
|
1112
|
+
name: name,
|
|
1113
|
+
lastname: lastname,
|
|
1114
|
+
nickname: nickname,
|
|
1115
|
+
tel_prefix: tel_prefix,
|
|
1116
|
+
tel_suffix: tel_suffix,
|
|
1117
|
+
language: language,
|
|
1118
|
+
avatar: avatar
|
|
1119
|
+
};
|
|
1120
|
+
_context2.next = 5;
|
|
1121
|
+
return setUpdateUserAction({
|
|
1122
|
+
dispatch: dispatch,
|
|
1123
|
+
domainName: domainName,
|
|
1124
|
+
user: user,
|
|
1125
|
+
token: token_ls
|
|
1126
|
+
});
|
|
1127
|
+
case 5:
|
|
1128
|
+
return _context2.abrupt("return", _context2.sent);
|
|
1129
|
+
case 6:
|
|
1130
|
+
case "end":
|
|
1131
|
+
return _context2.stop();
|
|
1132
|
+
}
|
|
1133
|
+
}, _callee2);
|
|
1134
|
+
}));
|
|
1135
|
+
return function (_x) {
|
|
1136
|
+
return _ref3.apply(this, arguments);
|
|
1125
1137
|
};
|
|
1126
|
-
|
|
1127
|
-
dispatch: dispatch,
|
|
1128
|
-
domainName: domainName,
|
|
1129
|
-
user: user,
|
|
1130
|
-
token: token_ls
|
|
1131
|
-
});
|
|
1132
|
-
}, [domainName]);
|
|
1138
|
+
}(), [domainName]);
|
|
1133
1139
|
var updateUserWithRedirect = useCallback(function () {
|
|
1134
|
-
var token_ls = localStorage.getItem(
|
|
1140
|
+
var token_ls = localStorage.getItem(TOKEN_LS);
|
|
1135
1141
|
if (!token_ls) return;
|
|
1136
1142
|
return window.location.replace(getClientBasePath({
|
|
1137
1143
|
domainName: domainName
|
|
1138
|
-
}) + "
|
|
1144
|
+
}) + "/" + routes.tenantUpdateUser + "/" + sid + "/" + token_ls);
|
|
1139
1145
|
}, [domainName, sid]);
|
|
1140
|
-
var sendEmailVerification = useCallback(function () {
|
|
1141
|
-
var token_ls
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
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]);
|
|
1149
1172
|
var memoProvider = useMemo(function () {
|
|
1150
1173
|
return _extends({}, dauthState, {
|
|
1151
1174
|
loginWithRedirect: loginWithRedirect,
|
|
1152
1175
|
logout: logout,
|
|
1153
|
-
getAccessToken:
|
|
1154
|
-
return _getAccessToken() || '';
|
|
1155
|
-
},
|
|
1176
|
+
getAccessToken: getAccessToken,
|
|
1156
1177
|
updateUser: updateUser,
|
|
1157
1178
|
updateUserWithRedirect: updateUserWithRedirect,
|
|
1158
1179
|
sendEmailVerification: sendEmailVerification
|
|
1159
1180
|
});
|
|
1160
|
-
}, [dauthState, loginWithRedirect, logout,
|
|
1181
|
+
}, [dauthState, loginWithRedirect, logout, getAccessToken, updateUser, updateUserWithRedirect, sendEmailVerification]);
|
|
1161
1182
|
return React.createElement(DauthContext.Provider, {
|
|
1162
1183
|
value: memoProvider
|
|
1163
1184
|
}, children);
|