@embedreach/components 0.1.98 → 0.1.99

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,42 @@ 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
+ useAuthContext(reauthCallback);
13657
+ return null;
13658
+ };
13623
13659
  const matchHtmlEntity = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34|nbsp|#160|copy|#169|reg|#174|hellip|#8230|#x2F|#47);/g;
13624
13660
  const htmlEntities = {
13625
13661
  "&": "&",
@@ -35684,7 +35720,8 @@ const ReachProvider = ({
35684
35720
  language,
35685
35721
  children: children2,
35686
35722
  theme: theme2,
35687
- debug
35723
+ debug,
35724
+ callbacks
35688
35725
  }) => {
35689
35726
  const [queryClient] = React__default.useState(() => {
35690
35727
  if (authToken2) {
@@ -35728,6 +35765,12 @@ const ReachProvider = ({
35728
35765
  language,
35729
35766
  initialLanguage: language?.default,
35730
35767
  children: /* @__PURE__ */ jsx(Provider$2, { initialTheme: theme2, children: /* @__PURE__ */ jsxs(Provider$3, { children: [
35768
+ /* @__PURE__ */ jsx(
35769
+ AuthCallbackHandler,
35770
+ {
35771
+ reauthCallback: callbacks?.onReauthRequested
35772
+ }
35773
+ ),
35731
35774
  children2,
35732
35775
  /* @__PURE__ */ jsx(Toaster, {})
35733
35776
  ] }) })