@vtex/faststore-plugin-buyer-portal 1.1.115 → 1.1.116

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vtex/faststore-plugin-buyer-portal",
3
- "version": "1.1.115",
3
+ "version": "1.1.116",
4
4
  "description": "A plugin for faststore with buyer portal",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -12,7 +12,6 @@ import { AUT_COOKIE_KEY } from "../utils/constants";
12
12
  */
13
13
  export const useCookieMonitor = () => {
14
14
  const [hasCookie, setHasCookie] = useState(false);
15
- const [timedOut, setTimedOut] = useState(false);
16
15
 
17
16
  useEffect(() => {
18
17
  const checkCookie = () => {
@@ -59,10 +58,7 @@ export const useCookieMonitor = () => {
59
58
 
60
59
  // Cleanup after 5 seconds max
61
60
  const timeout = setTimeout(() => {
62
- console.log(
63
- "[useCookieMonitor] Polling timeout reached (5s) - cookie never appeared"
64
- );
65
- setTimedOut(true);
61
+ console.log("[useCookieMonitor] Polling timeout reached (5s)");
66
62
  clearInterval(interval);
67
63
  }, 5000);
68
64
 
@@ -73,5 +69,5 @@ export const useCookieMonitor = () => {
73
69
  }
74
70
  }, []);
75
71
 
76
- return { hasCookie, timedOut };
72
+ return hasCookie;
77
73
  };
@@ -3,9 +3,4 @@ import { ClientContext } from "../utils";
3
3
  export type AuthRouteProps<T> =
4
4
  | { authorized: true; data: T; clientContext: ClientContext; loading: false }
5
5
  | { authorized: false; loading: false }
6
- | {
7
- authorized: false;
8
- loading: true;
9
- data?: Partial<T>;
10
- clientContext?: ClientContext;
11
- };
6
+ | { authorized: false; loading: true };
@@ -2,6 +2,7 @@ import { useEffect, useRef, type ComponentType } from "react";
2
2
 
3
3
  import { useRouter } from "next/router";
4
4
 
5
+ import { PageLoader } from "../components";
5
6
  import { useCookieMonitor } from "../hooks/useCookieMonitor";
6
7
 
7
8
  import type { AuthRouteProps } from "../types";
@@ -15,7 +16,7 @@ export const withAuth = <T extends Record<string, unknown>>(
15
16
  ) => {
16
17
  return function AuthenticatedComponent(props: AuthRouteProps<T>) {
17
18
  const router = useRouter();
18
- const { hasCookie, timedOut } = useCookieMonitor();
19
+ const hasCookie = useCookieMonitor();
19
20
  const reloadAttemptedRef = useRef(false);
20
21
 
21
22
  // Debug logging
@@ -24,10 +25,9 @@ export const withAuth = <T extends Record<string, unknown>>(
24
25
  authorized: props?.authorized,
25
26
  loading: props?.loading,
26
27
  hasCookie,
27
- timedOut,
28
28
  reloadAttempted: reloadAttemptedRef.current,
29
29
  });
30
- }, [props?.authorized, props?.loading, hasCookie, timedOut]);
30
+ }, [props?.authorized, props?.loading, hasCookie]);
31
31
 
32
32
  useEffect(() => {
33
33
  // If not authorized and not loading, reload the page
@@ -56,28 +56,14 @@ export const withAuth = <T extends Record<string, unknown>>(
56
56
  }
57
57
  }, [props?.loading, hasCookie, router]);
58
58
 
59
- useEffect(() => {
60
- // If we're in loading state and timeout reached, redirect to home
61
- if (props?.loading && timedOut && !reloadAttemptedRef.current) {
62
- console.log("[withAuth] Cookie timeout - redirecting to home page");
63
- reloadAttemptedRef.current = true;
64
- router.push("/");
59
+ if (!props?.authorized) {
60
+ if (props?.loading) {
61
+ return <PageLoader />;
65
62
  }
66
- }, [props?.loading, timedOut, router]);
67
-
68
- // Always render the component, but pass loading state
69
- // This allows components to handle their own loading states
70
- if (!props?.authorized && !props?.loading) {
71
- // Not authorized and not loading = permanently denied
72
63
  return null;
73
64
  }
74
65
 
75
- // Render with whatever data we have (might be empty/partial if loading)
76
- const componentProps = {
77
- ...(props?.data || ({} as T)),
78
- loading: props?.loading || false,
79
- } as T & { loading: boolean };
80
-
81
- return <Component {...componentProps} />;
66
+ // If authorized, render the component with the data
67
+ return <Component {...(props.data as T)} />;
82
68
  };
83
69
  };
@@ -2,7 +2,7 @@ import { useEffect, useRef, type ComponentType } from "react";
2
2
 
3
3
  import { useRouter } from "next/router";
4
4
 
5
- import { BuyerPortalProvider } from "../components";
5
+ import { BuyerPortalProvider, PageLoader } from "../components";
6
6
  import { useCookieMonitor } from "../hooks/useCookieMonitor";
7
7
 
8
8
  import type { AuthRouteProps } from "../types";
@@ -18,7 +18,7 @@ export const withAuthProvider = <T,>(
18
18
  ) => {
19
19
  return function WrappedPage(props: AuthRouteProps<T>) {
20
20
  const router = useRouter();
21
- const { hasCookie, timedOut } = useCookieMonitor();
21
+ const hasCookie = useCookieMonitor();
22
22
  const reloadAttemptedRef = useRef(false);
23
23
  const isProduction = process.env.NODE_ENV === "production";
24
24
 
@@ -29,7 +29,6 @@ export const withAuthProvider = <T,>(
29
29
  authorized: props?.authorized,
30
30
  loading: props?.loading,
31
31
  hasCookie,
32
- timedOut,
33
32
  reloadAttempted: reloadAttemptedRef.current,
34
33
  routerPath: router.asPath,
35
34
  });
@@ -38,7 +37,6 @@ export const withAuthProvider = <T,>(
38
37
  props?.authorized,
39
38
  props?.loading,
40
39
  hasCookie,
41
- timedOut,
42
40
  router.asPath,
43
41
  isProduction,
44
42
  ]);
@@ -73,35 +71,17 @@ export const withAuthProvider = <T,>(
73
71
  }
74
72
  }, [props?.loading, hasCookie, router]);
75
73
 
76
- useEffect(() => {
77
- // If we're in loading state and timeout reached, redirect to home
78
- if (props?.loading && timedOut && !reloadAttemptedRef.current) {
79
- console.log(
80
- "[withAuthProvider] Cookie timeout - redirecting to home page"
81
- );
82
- reloadAttemptedRef.current = true;
83
- router.push("/");
74
+ if (!props?.authorized) {
75
+ if (props?.loading) {
76
+ console.log("[withAuthProvider] Loading state");
77
+ return <PageLoader />;
84
78
  }
85
- }, [props?.loading, timedOut, router]);
86
-
87
- // Always render the component, but pass loading state
88
- // This allows components to handle their own loading states
89
- if (!props?.authorized && !props?.loading) {
90
- // Not authorized and not loading = permanently denied
91
79
  return null;
92
80
  }
93
81
 
94
- // Render with whatever data we have (might be empty/partial if loading)
95
- const componentProps = {
96
- ...(props?.data || ({} as T)),
97
- loading: props?.loading || false,
98
- } as T & { loading: boolean };
99
-
100
- const clientContext = props?.clientContext || ({} as ClientContext);
101
-
102
82
  return (
103
- <BuyerPortalProvider clientContext={clientContext}>
104
- <Component {...componentProps} clientContext={clientContext} />
83
+ <BuyerPortalProvider clientContext={props?.clientContext}>
84
+ <Component {...props.data} clientContext={props?.clientContext} />
105
85
  </BuyerPortalProvider>
106
86
  );
107
87
  };