@embedreach/components 0.1.98 → 0.1.100

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.
@@ -13050,7 +13050,7 @@ const authListeners = [
13050
13050
  }
13051
13051
  }
13052
13052
  ];
13053
- const { Provider: Provider$3 } = createDataContext(
13053
+ const { Context: Context$2, Provider: Provider$3 } = createDataContext(
13054
13054
  authReducer,
13055
13055
  {
13056
13056
  handleReauth
@@ -13620,6 +13620,44 @@ const ThemeInitializer = ({ initialTheme, children: children2 }) => {
13620
13620
  const Provider$2 = ({ initialTheme, children: children2 }) => {
13621
13621
  return /* @__PURE__ */ jsx(BaseProvider, { children: /* @__PURE__ */ jsx(ThemeInitializer, { initialTheme, children: children2 }) });
13622
13622
  };
13623
+ const useAuthContext = (reauthCallback) => {
13624
+ const context2 = useContext$1(Context$2);
13625
+ const hasTriedReauth = useRef(false);
13626
+ const callbackRef = useRef(reauthCallback);
13627
+ useEffect(() => {
13628
+ callbackRef.current = reauthCallback;
13629
+ }, [reauthCallback]);
13630
+ if (context2 === void 0) {
13631
+ throw new Error("useAuthContext must be used within an AuthProvider");
13632
+ }
13633
+ const { state, handleReauth: handleReauth2 } = context2;
13634
+ useEffect(() => {
13635
+ if (!state.isAuthenticated && state.reauthing && !hasTriedReauth.current) {
13636
+ hasTriedReauth.current = true;
13637
+ if (callbackRef.current) {
13638
+ handleReauth2(callbackRef.current);
13639
+ } else {
13640
+ console.error("No reauth callback available");
13641
+ }
13642
+ const timeout = setTimeout(() => {
13643
+ hasTriedReauth.current = false;
13644
+ }, 1e4);
13645
+ return () => clearTimeout(timeout);
13646
+ }
13647
+ }, [state.isAuthenticated, state.reauthing, handleReauth2]);
13648
+ useEffect(() => {
13649
+ if (state.isAuthenticated && hasTriedReauth.current) {
13650
+ hasTriedReauth.current = false;
13651
+ }
13652
+ }, [state.isAuthenticated]);
13653
+ return context2;
13654
+ };
13655
+ const AuthCallbackHandler = ({ reauthCallback }) => {
13656
+ console.log(`>>>HERE`, reauthCallback);
13657
+ useAuthContext(reauthCallback);
13658
+ console.log(`>>>HERE2`, reauthCallback);
13659
+ return null;
13660
+ };
13623
13661
  const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
13624
13662
  const htmlEntities = {
13625
13663
  "&": "&",
@@ -35684,7 +35722,8 @@ const ReachProvider = ({
35684
35722
  language,
35685
35723
  children: children2,
35686
35724
  theme: theme2,
35687
- debug
35725
+ debug,
35726
+ callbacks
35688
35727
  }) => {
35689
35728
  const [queryClient] = React__default.useState(() => {
35690
35729
  if (authToken2) {
@@ -35728,6 +35767,12 @@ const ReachProvider = ({
35728
35767
  language,
35729
35768
  initialLanguage: language?.default,
35730
35769
  children: /* @__PURE__ */ jsx(Provider$2, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$3, { children: [
35770
+ /* @__PURE__ */ jsx(
35771
+ AuthCallbackHandler,
35772
+ {
35773
+ reauthCallback: callbacks?.onReauthRequested
35774
+ }
35775
+ ),
35731
35776
  children2,
35732
35777
  /* @__PURE__ */ jsx(Toaster, {})
35733
35778
  ] }) })