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
package/dist/constants.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const TOKEN_LS = "dauth_state";
|
|
@@ -363,9 +363,11 @@ var initialDauthState = {
|
|
|
363
363
|
loginWithRedirect: function loginWithRedirect() {},
|
|
364
364
|
logout: function logout() {},
|
|
365
365
|
getAccessToken: function getAccessToken() {
|
|
366
|
-
return
|
|
366
|
+
return Promise.resolve('');
|
|
367
|
+
},
|
|
368
|
+
updateUser: function updateUser() {
|
|
369
|
+
return Promise.resolve(false);
|
|
367
370
|
},
|
|
368
|
-
updateUser: function updateUser() {},
|
|
369
371
|
updateUserWithRedirect: function updateUserWithRedirect() {},
|
|
370
372
|
// Send email verification
|
|
371
373
|
sendEmailVerificationStatus: {
|
|
@@ -375,7 +377,9 @@ var initialDauthState = {
|
|
|
375
377
|
},
|
|
376
378
|
isLoading: false
|
|
377
379
|
},
|
|
378
|
-
sendEmailVerification: function sendEmailVerification() {
|
|
380
|
+
sendEmailVerification: function sendEmailVerification() {
|
|
381
|
+
return Promise.resolve(false);
|
|
382
|
+
}
|
|
379
383
|
};
|
|
380
384
|
|
|
381
385
|
var LOGIN = 'LOGIN';
|
|
@@ -615,18 +619,18 @@ var refreshAccessTokenAPI = /*#__PURE__*/function () {
|
|
|
615
619
|
};
|
|
616
620
|
}();
|
|
617
621
|
|
|
618
|
-
var
|
|
622
|
+
var TOKEN_LS = 'dauth_state';
|
|
619
623
|
|
|
620
624
|
function setDauthStateAction(_x) {
|
|
621
625
|
return _setDauthStateAction.apply(this, arguments);
|
|
622
626
|
}
|
|
623
627
|
function _setDauthStateAction() {
|
|
624
628
|
_setDauthStateAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
625
|
-
var dispatch,
|
|
629
|
+
var dispatch, token, domainName, getUserFetch;
|
|
626
630
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
627
631
|
while (1) switch (_context.prev = _context.next) {
|
|
628
632
|
case 0:
|
|
629
|
-
dispatch = _ref.dispatch,
|
|
633
|
+
dispatch = _ref.dispatch, token = _ref.token, domainName = _ref.domainName;
|
|
630
634
|
dispatch({
|
|
631
635
|
type: SET_IS_LOADING,
|
|
632
636
|
payload: {
|
|
@@ -635,7 +639,7 @@ function _setDauthStateAction() {
|
|
|
635
639
|
});
|
|
636
640
|
_context.prev = 2;
|
|
637
641
|
_context.next = 5;
|
|
638
|
-
return getUserAPI(domainName,
|
|
642
|
+
return getUserAPI(domainName, token);
|
|
639
643
|
case 5:
|
|
640
644
|
getUserFetch = _context.sent;
|
|
641
645
|
if (!(getUserFetch.response.status === 200)) {
|
|
@@ -651,7 +655,7 @@ function _setDauthStateAction() {
|
|
|
651
655
|
}
|
|
652
656
|
});
|
|
653
657
|
window.history.replaceState({}, document.title, getUserFetch.data.domain.loginRedirect);
|
|
654
|
-
return _context.abrupt("return", localStorage.setItem(
|
|
658
|
+
return _context.abrupt("return", localStorage.setItem(TOKEN_LS, token));
|
|
655
659
|
case 12:
|
|
656
660
|
return _context.abrupt("return", resetUser(dispatch));
|
|
657
661
|
case 13:
|
|
@@ -720,7 +724,7 @@ function _setAutoLoginAction() {
|
|
|
720
724
|
isAuthenticated: true
|
|
721
725
|
}
|
|
722
726
|
});
|
|
723
|
-
localStorage.setItem(
|
|
727
|
+
localStorage.setItem(TOKEN_LS, refreshAccessTokenFetch.data.accessToken);
|
|
724
728
|
return _context2.abrupt("return");
|
|
725
729
|
case 16:
|
|
726
730
|
window.location.replace(getClientBasePath({
|
|
@@ -760,108 +764,96 @@ function _setAutoLoginAction() {
|
|
|
760
764
|
}));
|
|
761
765
|
return _setAutoLoginAction.apply(this, arguments);
|
|
762
766
|
}
|
|
763
|
-
function setLogoutAction(
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
});
|
|
789
|
-
localStorage.removeItem(DAUTH_STATE);
|
|
790
|
-
return _context3.abrupt("return", dispatch({
|
|
791
|
-
type: SET_IS_LOADING,
|
|
792
|
-
payload: {
|
|
793
|
-
isLoading: false
|
|
794
|
-
}
|
|
795
|
-
}));
|
|
796
|
-
case 5:
|
|
797
|
-
case "end":
|
|
798
|
-
return _context3.stop();
|
|
799
|
-
}
|
|
800
|
-
}, _callee3);
|
|
801
|
-
}));
|
|
802
|
-
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
|
+
});
|
|
803
792
|
}
|
|
804
|
-
function setUpdateUserAction(
|
|
793
|
+
function setUpdateUserAction(_x3) {
|
|
805
794
|
return _setUpdateUserAction.apply(this, arguments);
|
|
806
795
|
}
|
|
807
796
|
function _setUpdateUserAction() {
|
|
808
|
-
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
797
|
+
_setUpdateUserAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref4) {
|
|
809
798
|
var dispatch, domainName, user, token, getUserFetch;
|
|
810
|
-
return _regeneratorRuntime().wrap(function
|
|
811
|
-
while (1) switch (
|
|
799
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
800
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
812
801
|
case 0:
|
|
813
802
|
dispatch = _ref4.dispatch, domainName = _ref4.domainName, user = _ref4.user, token = _ref4.token;
|
|
814
803
|
if (user.language) {
|
|
815
804
|
window.document.documentElement.setAttribute('lang', user.language);
|
|
816
805
|
}
|
|
817
806
|
if (token) {
|
|
818
|
-
|
|
807
|
+
_context3.next = 5;
|
|
819
808
|
break;
|
|
820
809
|
}
|
|
821
|
-
|
|
810
|
+
dispatch({
|
|
822
811
|
type: UPDATE_USER,
|
|
823
812
|
payload: user
|
|
824
|
-
})
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
813
|
+
});
|
|
814
|
+
return _context3.abrupt("return", false);
|
|
815
|
+
case 5:
|
|
816
|
+
_context3.prev = 5;
|
|
817
|
+
_context3.next = 8;
|
|
828
818
|
return updateUserAPI(domainName, user, token);
|
|
829
|
-
case
|
|
830
|
-
getUserFetch =
|
|
819
|
+
case 8:
|
|
820
|
+
getUserFetch = _context3.sent;
|
|
831
821
|
if (!(getUserFetch.response.status === 200)) {
|
|
832
|
-
|
|
822
|
+
_context3.next = 14;
|
|
833
823
|
break;
|
|
834
824
|
}
|
|
835
|
-
|
|
825
|
+
dispatch({
|
|
836
826
|
type: UPDATE_USER,
|
|
837
827
|
payload: getUserFetch.data.user
|
|
838
|
-
})
|
|
839
|
-
|
|
840
|
-
console.log('Update user error', getUserFetch.data.message);
|
|
841
|
-
return _context4.abrupt("return");
|
|
828
|
+
});
|
|
829
|
+
return _context3.abrupt("return", true);
|
|
842
830
|
case 14:
|
|
843
|
-
|
|
844
|
-
|
|
831
|
+
console.log('Update user error', getUserFetch.data.message);
|
|
832
|
+
return _context3.abrupt("return", false);
|
|
845
833
|
case 16:
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
834
|
+
_context3.next = 22;
|
|
835
|
+
break;
|
|
836
|
+
case 18:
|
|
837
|
+
_context3.prev = 18;
|
|
838
|
+
_context3.t0 = _context3["catch"](5);
|
|
839
|
+
console.log('Update user error', _context3.t0);
|
|
840
|
+
return _context3.abrupt("return", false);
|
|
841
|
+
case 22:
|
|
850
842
|
case "end":
|
|
851
|
-
return
|
|
843
|
+
return _context3.stop();
|
|
852
844
|
}
|
|
853
|
-
},
|
|
845
|
+
}, _callee3, null, [[5, 18]]);
|
|
854
846
|
}));
|
|
855
847
|
return _setUpdateUserAction.apply(this, arguments);
|
|
856
848
|
}
|
|
857
|
-
function sendEmailVerificationAction(
|
|
849
|
+
function sendEmailVerificationAction(_x4) {
|
|
858
850
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
859
851
|
}
|
|
860
852
|
function _sendEmailVerificationAction() {
|
|
861
|
-
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
853
|
+
_sendEmailVerificationAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref5) {
|
|
862
854
|
var dispatch, domainName, token, sendEmailFetch;
|
|
863
|
-
return _regeneratorRuntime().wrap(function
|
|
864
|
-
while (1) switch (
|
|
855
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
856
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
865
857
|
case 0:
|
|
866
858
|
dispatch = _ref5.dispatch, domainName = _ref5.domainName, token = _ref5.token;
|
|
867
859
|
dispatch({
|
|
@@ -875,13 +867,13 @@ function _sendEmailVerificationAction() {
|
|
|
875
867
|
message: 'Sending email verification...'
|
|
876
868
|
}
|
|
877
869
|
});
|
|
878
|
-
|
|
879
|
-
|
|
870
|
+
_context4.prev = 3;
|
|
871
|
+
_context4.next = 6;
|
|
880
872
|
return sendEmailVerificationAPI(domainName, token);
|
|
881
873
|
case 6:
|
|
882
|
-
sendEmailFetch =
|
|
874
|
+
sendEmailFetch = _context4.sent;
|
|
883
875
|
if (!(sendEmailFetch.response.status === 200)) {
|
|
884
|
-
|
|
876
|
+
_context4.next = 13;
|
|
885
877
|
break;
|
|
886
878
|
}
|
|
887
879
|
dispatch({
|
|
@@ -891,11 +883,12 @@ function _sendEmailVerificationAction() {
|
|
|
891
883
|
message: sendEmailFetch.data.message
|
|
892
884
|
}
|
|
893
885
|
});
|
|
894
|
-
|
|
886
|
+
dispatch({
|
|
895
887
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
896
888
|
payload: false
|
|
897
|
-
})
|
|
898
|
-
|
|
889
|
+
});
|
|
890
|
+
return _context4.abrupt("return", true);
|
|
891
|
+
case 13:
|
|
899
892
|
dispatch({
|
|
900
893
|
type: SET_SEND_EMAIL_VERIFICATION_STATUS,
|
|
901
894
|
payload: {
|
|
@@ -903,16 +896,17 @@ function _sendEmailVerificationAction() {
|
|
|
903
896
|
message: sendEmailFetch.data.message
|
|
904
897
|
}
|
|
905
898
|
});
|
|
906
|
-
|
|
899
|
+
dispatch({
|
|
907
900
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
908
901
|
payload: false
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
_context5.next = 20;
|
|
912
|
-
break;
|
|
902
|
+
});
|
|
903
|
+
return _context4.abrupt("return", false);
|
|
913
904
|
case 16:
|
|
914
|
-
|
|
915
|
-
|
|
905
|
+
_context4.next = 23;
|
|
906
|
+
break;
|
|
907
|
+
case 18:
|
|
908
|
+
_context4.prev = 18;
|
|
909
|
+
_context4.t0 = _context4["catch"](3);
|
|
916
910
|
dispatch({
|
|
917
911
|
type: SET_SEND_EMAIL_VERIFICATION_STATUS,
|
|
918
912
|
payload: {
|
|
@@ -920,109 +914,110 @@ function _sendEmailVerificationAction() {
|
|
|
920
914
|
message: 'Send email verification fetch error'
|
|
921
915
|
}
|
|
922
916
|
});
|
|
923
|
-
|
|
917
|
+
dispatch({
|
|
924
918
|
type: SET_SEND_EMAIL_VERIFICATION_IS_LOADING,
|
|
925
919
|
payload: false
|
|
926
|
-
})
|
|
927
|
-
|
|
920
|
+
});
|
|
921
|
+
return _context4.abrupt("return", false);
|
|
922
|
+
case 23:
|
|
928
923
|
case "end":
|
|
929
|
-
return
|
|
924
|
+
return _context4.stop();
|
|
930
925
|
}
|
|
931
|
-
},
|
|
926
|
+
}, _callee4, null, [[3, 18]]);
|
|
932
927
|
}));
|
|
933
928
|
return _sendEmailVerificationAction.apply(this, arguments);
|
|
934
929
|
}
|
|
935
|
-
function checkTokenAction(
|
|
930
|
+
function checkTokenAction(_x5) {
|
|
936
931
|
return _checkTokenAction.apply(this, arguments);
|
|
937
932
|
}
|
|
938
933
|
function _checkTokenAction() {
|
|
939
|
-
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
934
|
+
_checkTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(_ref6) {
|
|
940
935
|
var dispatch, domainName, sid, token, refreshAccessTokenFetch;
|
|
941
|
-
return _regeneratorRuntime().wrap(function
|
|
942
|
-
while (1) switch (
|
|
936
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
937
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
943
938
|
case 0:
|
|
944
939
|
dispatch = _ref6.dispatch, domainName = _ref6.domainName, sid = _ref6.sid, token = _ref6.token;
|
|
945
|
-
|
|
946
|
-
|
|
940
|
+
_context5.prev = 1;
|
|
941
|
+
_context5.next = 4;
|
|
947
942
|
return refreshAccessTokenAPI(domainName, token);
|
|
948
943
|
case 4:
|
|
949
|
-
refreshAccessTokenFetch =
|
|
944
|
+
refreshAccessTokenFetch = _context5.sent;
|
|
950
945
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
951
|
-
|
|
946
|
+
_context5.next = 9;
|
|
952
947
|
break;
|
|
953
948
|
}
|
|
954
|
-
return
|
|
949
|
+
return _context5.abrupt("return");
|
|
955
950
|
case 9:
|
|
956
951
|
window.location.replace(getClientBasePath({
|
|
957
952
|
domainName: domainName
|
|
958
953
|
}) + "/" + routes.tenantSignin + "/" + sid);
|
|
959
|
-
return
|
|
954
|
+
return _context5.abrupt("return", resetUser(dispatch));
|
|
960
955
|
case 11:
|
|
961
|
-
|
|
956
|
+
_context5.next = 17;
|
|
962
957
|
break;
|
|
963
958
|
case 13:
|
|
964
|
-
|
|
965
|
-
|
|
959
|
+
_context5.prev = 13;
|
|
960
|
+
_context5.t0 = _context5["catch"](1);
|
|
966
961
|
resetUser(dispatch);
|
|
967
|
-
throw
|
|
962
|
+
throw _context5.t0;
|
|
968
963
|
case 17:
|
|
969
964
|
case "end":
|
|
970
|
-
return
|
|
965
|
+
return _context5.stop();
|
|
971
966
|
}
|
|
972
|
-
},
|
|
967
|
+
}, _callee5, null, [[1, 13]]);
|
|
973
968
|
}));
|
|
974
969
|
return _checkTokenAction.apply(this, arguments);
|
|
975
970
|
}
|
|
976
|
-
function getAccessTokenAction(
|
|
971
|
+
function getAccessTokenAction(_x6) {
|
|
977
972
|
return _getAccessTokenAction.apply(this, arguments);
|
|
978
973
|
}
|
|
979
974
|
///////////////////////////////////////////
|
|
980
975
|
//////////////////////////////////////////
|
|
981
976
|
function _getAccessTokenAction() {
|
|
982
|
-
_getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
977
|
+
_getAccessTokenAction = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref7) {
|
|
983
978
|
var dispatch, domainName, token_ls, refreshAccessTokenFetch, _refreshAccessTokenFe;
|
|
984
|
-
return _regeneratorRuntime().wrap(function
|
|
985
|
-
while (1) switch (
|
|
979
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
980
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
986
981
|
case 0:
|
|
987
982
|
dispatch = _ref7.dispatch, domainName = _ref7.domainName;
|
|
988
|
-
token_ls = localStorage.getItem(
|
|
983
|
+
token_ls = localStorage.getItem(TOKEN_LS);
|
|
989
984
|
if (token_ls) {
|
|
990
|
-
|
|
985
|
+
_context6.next = 4;
|
|
991
986
|
break;
|
|
992
987
|
}
|
|
993
|
-
return
|
|
988
|
+
return _context6.abrupt("return");
|
|
994
989
|
case 4:
|
|
995
|
-
|
|
996
|
-
|
|
990
|
+
_context6.prev = 4;
|
|
991
|
+
_context6.next = 7;
|
|
997
992
|
return refreshAccessTokenAPI(domainName, token_ls);
|
|
998
993
|
case 7:
|
|
999
|
-
refreshAccessTokenFetch =
|
|
994
|
+
refreshAccessTokenFetch = _context6.sent;
|
|
1000
995
|
if (!(refreshAccessTokenFetch.response.status === 200)) {
|
|
1001
|
-
|
|
996
|
+
_context6.next = 12;
|
|
1002
997
|
break;
|
|
1003
998
|
}
|
|
1004
|
-
return
|
|
999
|
+
return _context6.abrupt("return", (_refreshAccessTokenFe = refreshAccessTokenFetch.data.accessToken) != null ? _refreshAccessTokenFe : token_ls);
|
|
1005
1000
|
case 12:
|
|
1006
1001
|
resetUser(dispatch);
|
|
1007
|
-
return
|
|
1002
|
+
return _context6.abrupt("return", 'token-not-found');
|
|
1008
1003
|
case 14:
|
|
1009
|
-
|
|
1004
|
+
_context6.next = 20;
|
|
1010
1005
|
break;
|
|
1011
1006
|
case 16:
|
|
1012
|
-
|
|
1013
|
-
|
|
1007
|
+
_context6.prev = 16;
|
|
1008
|
+
_context6.t0 = _context6["catch"](4);
|
|
1014
1009
|
resetUser(dispatch);
|
|
1015
|
-
throw
|
|
1010
|
+
throw _context6.t0;
|
|
1016
1011
|
case 20:
|
|
1017
1012
|
case "end":
|
|
1018
|
-
return
|
|
1013
|
+
return _context6.stop();
|
|
1019
1014
|
}
|
|
1020
|
-
},
|
|
1015
|
+
}, _callee6, null, [[4, 16]]);
|
|
1021
1016
|
}));
|
|
1022
1017
|
return _getAccessTokenAction.apply(this, arguments);
|
|
1023
1018
|
}
|
|
1024
1019
|
var resetUser = function resetUser(dispatch) {
|
|
1025
|
-
localStorage.removeItem(
|
|
1020
|
+
localStorage.removeItem(TOKEN_LS);
|
|
1026
1021
|
return dispatch({
|
|
1027
1022
|
type: LOGIN,
|
|
1028
1023
|
payload: {
|
|
@@ -1044,7 +1039,7 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1044
1039
|
React.useEffect(function () {
|
|
1045
1040
|
if (!dauthState.isAuthenticated) return;
|
|
1046
1041
|
var interval = setInterval(function () {
|
|
1047
|
-
var token_ls = localStorage.getItem(
|
|
1042
|
+
var token_ls = localStorage.getItem(TOKEN_LS);
|
|
1048
1043
|
if (!token_ls) return;
|
|
1049
1044
|
checkTokenAction({
|
|
1050
1045
|
dispatch: dispatch,
|
|
@@ -1062,18 +1057,18 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1062
1057
|
var queryString = window.location.search;
|
|
1063
1058
|
if (!queryString) return;
|
|
1064
1059
|
var urlParams = new URLSearchParams(queryString);
|
|
1065
|
-
var
|
|
1066
|
-
if (
|
|
1060
|
+
var token_url = urlParams.get(TOKEN_LS);
|
|
1061
|
+
if (token_url && !dauthState.isAuthenticated) {
|
|
1067
1062
|
setDauthStateAction({
|
|
1068
1063
|
dispatch: dispatch,
|
|
1069
|
-
|
|
1064
|
+
token: token_url,
|
|
1070
1065
|
domainName: domainName
|
|
1071
1066
|
});
|
|
1072
1067
|
}
|
|
1073
1068
|
}, []);
|
|
1074
1069
|
// Auto Login
|
|
1075
1070
|
React.useEffect(function () {
|
|
1076
|
-
var dauth_state_ls = localStorage.getItem(
|
|
1071
|
+
var dauth_state_ls = localStorage.getItem(TOKEN_LS);
|
|
1077
1072
|
if (dauth_state_ls && !dauthState.isAuthenticated) {
|
|
1078
1073
|
setAutoLoginAction({
|
|
1079
1074
|
dispatch: dispatch,
|
|
@@ -1093,7 +1088,7 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1093
1088
|
dispatch: dispatch
|
|
1094
1089
|
});
|
|
1095
1090
|
}, []);
|
|
1096
|
-
var
|
|
1091
|
+
var getAccessToken = React.useCallback( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
1097
1092
|
var token;
|
|
1098
1093
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
1099
1094
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -1112,59 +1107,85 @@ var DauthProvider = function DauthProvider(props) {
|
|
|
1112
1107
|
}
|
|
1113
1108
|
}, _callee);
|
|
1114
1109
|
})), []);
|
|
1115
|
-
var updateUser = React.useCallback(function (
|
|
1116
|
-
var
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1110
|
+
var updateUser = React.useCallback( /*#__PURE__*/function () {
|
|
1111
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
|
1112
|
+
var name, lastname, nickname, tel_prefix, tel_suffix, language, avatar, token_ls, user;
|
|
1113
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
1114
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
1115
|
+
case 0:
|
|
1116
|
+
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;
|
|
1117
|
+
token_ls = localStorage.getItem(TOKEN_LS);
|
|
1118
|
+
user = {
|
|
1119
|
+
name: name,
|
|
1120
|
+
lastname: lastname,
|
|
1121
|
+
nickname: nickname,
|
|
1122
|
+
tel_prefix: tel_prefix,
|
|
1123
|
+
tel_suffix: tel_suffix,
|
|
1124
|
+
language: language,
|
|
1125
|
+
avatar: avatar
|
|
1126
|
+
};
|
|
1127
|
+
_context2.next = 5;
|
|
1128
|
+
return setUpdateUserAction({
|
|
1129
|
+
dispatch: dispatch,
|
|
1130
|
+
domainName: domainName,
|
|
1131
|
+
user: user,
|
|
1132
|
+
token: token_ls
|
|
1133
|
+
});
|
|
1134
|
+
case 5:
|
|
1135
|
+
return _context2.abrupt("return", _context2.sent);
|
|
1136
|
+
case 6:
|
|
1137
|
+
case "end":
|
|
1138
|
+
return _context2.stop();
|
|
1139
|
+
}
|
|
1140
|
+
}, _callee2);
|
|
1141
|
+
}));
|
|
1142
|
+
return function (_x) {
|
|
1143
|
+
return _ref3.apply(this, arguments);
|
|
1132
1144
|
};
|
|
1133
|
-
|
|
1134
|
-
dispatch: dispatch,
|
|
1135
|
-
domainName: domainName,
|
|
1136
|
-
user: user,
|
|
1137
|
-
token: token_ls
|
|
1138
|
-
});
|
|
1139
|
-
}, [domainName]);
|
|
1145
|
+
}(), [domainName]);
|
|
1140
1146
|
var updateUserWithRedirect = React.useCallback(function () {
|
|
1141
|
-
var token_ls = localStorage.getItem(
|
|
1147
|
+
var token_ls = localStorage.getItem(TOKEN_LS);
|
|
1142
1148
|
if (!token_ls) return;
|
|
1143
1149
|
return window.location.replace(getClientBasePath({
|
|
1144
1150
|
domainName: domainName
|
|
1145
|
-
}) + "
|
|
1151
|
+
}) + "/" + routes.tenantUpdateUser + "/" + sid + "/" + token_ls);
|
|
1146
1152
|
}, [domainName, sid]);
|
|
1147
|
-
var sendEmailVerification = React.useCallback(function () {
|
|
1148
|
-
var token_ls
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
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]);
|
|
1156
1179
|
var memoProvider = React.useMemo(function () {
|
|
1157
1180
|
return _extends({}, dauthState, {
|
|
1158
1181
|
loginWithRedirect: loginWithRedirect,
|
|
1159
1182
|
logout: logout,
|
|
1160
|
-
getAccessToken:
|
|
1161
|
-
return _getAccessToken() || '';
|
|
1162
|
-
},
|
|
1183
|
+
getAccessToken: getAccessToken,
|
|
1163
1184
|
updateUser: updateUser,
|
|
1164
1185
|
updateUserWithRedirect: updateUserWithRedirect,
|
|
1165
1186
|
sendEmailVerification: sendEmailVerification
|
|
1166
1187
|
});
|
|
1167
|
-
}, [dauthState, loginWithRedirect, logout,
|
|
1188
|
+
}, [dauthState, loginWithRedirect, logout, getAccessToken, updateUser, updateUserWithRedirect, sendEmailVerification]);
|
|
1168
1189
|
return React__default.createElement(DauthContext.Provider, {
|
|
1169
1190
|
value: memoProvider
|
|
1170
1191
|
}, children);
|