@vtex/faststore-plugin-buyer-portal 1.1.113 → 1.1.114
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
|
@@ -24,19 +24,33 @@ export const useCookieMonitor = () => {
|
|
|
24
24
|
cookie.trim().startsWith(`${cookieName}=`)
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const hasCookieValue =
|
|
28
|
+
!!authCookie && authCookie.split("=")[1]?.trim() !== "";
|
|
29
|
+
|
|
30
|
+
console.log("[useCookieMonitor] Checking cookie:", {
|
|
31
|
+
cookieName,
|
|
32
|
+
hasCookie: hasCookieValue,
|
|
33
|
+
cookieValue: authCookie
|
|
34
|
+
? authCookie.split("=")[1]?.substring(0, 10) + "..."
|
|
35
|
+
: "none",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
return hasCookieValue;
|
|
28
39
|
};
|
|
29
40
|
|
|
30
41
|
// Check immediately
|
|
31
42
|
const initialCheck = checkCookie();
|
|
43
|
+
console.log("[useCookieMonitor] Initial check:", initialCheck);
|
|
32
44
|
setHasCookie(initialCheck);
|
|
33
45
|
|
|
34
46
|
// If no cookie yet, poll for it
|
|
35
47
|
if (!initialCheck) {
|
|
48
|
+
console.log("[useCookieMonitor] Starting cookie polling...");
|
|
36
49
|
const interval = setInterval(() => {
|
|
37
50
|
const hasAuthCookie = checkCookie();
|
|
38
51
|
|
|
39
52
|
if (hasAuthCookie) {
|
|
53
|
+
console.log("[useCookieMonitor] Cookie found! Stopping poll.");
|
|
40
54
|
setHasCookie(true);
|
|
41
55
|
clearInterval(interval);
|
|
42
56
|
}
|
|
@@ -44,6 +58,7 @@ export const useCookieMonitor = () => {
|
|
|
44
58
|
|
|
45
59
|
// Cleanup after 5 seconds max
|
|
46
60
|
const timeout = setTimeout(() => {
|
|
61
|
+
console.log("[useCookieMonitor] Polling timeout reached (5s)");
|
|
47
62
|
clearInterval(interval);
|
|
48
63
|
}, 5000);
|
|
49
64
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, type ComponentType } from "react";
|
|
1
|
+
import { useEffect, useRef, type ComponentType } from "react";
|
|
2
2
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
@@ -17,17 +17,42 @@ export const withAuth = <T extends Record<string, unknown>>(
|
|
|
17
17
|
return function AuthenticatedComponent(props: AuthRouteProps<T>) {
|
|
18
18
|
const router = useRouter();
|
|
19
19
|
const hasCookie = useCookieMonitor();
|
|
20
|
+
const reloadAttemptedRef = useRef(false);
|
|
21
|
+
|
|
22
|
+
// Debug logging
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
console.log("[withAuth] Props state:", {
|
|
25
|
+
authorized: props?.authorized,
|
|
26
|
+
loading: props?.loading,
|
|
27
|
+
hasCookie,
|
|
28
|
+
reloadAttempted: reloadAttemptedRef.current,
|
|
29
|
+
});
|
|
30
|
+
}, [props?.authorized, props?.loading, hasCookie]);
|
|
20
31
|
|
|
21
32
|
useEffect(() => {
|
|
22
33
|
// If not authorized and not loading, reload the page
|
|
23
|
-
if (
|
|
24
|
-
|
|
34
|
+
if (
|
|
35
|
+
!props?.authorized &&
|
|
36
|
+
!props?.loading &&
|
|
37
|
+
!reloadAttemptedRef.current
|
|
38
|
+
) {
|
|
39
|
+
console.log("[withAuth] Reloading: not authorized and not loading");
|
|
40
|
+
reloadAttemptedRef.current = true;
|
|
41
|
+
// Use replace to bypass Next.js data cache
|
|
42
|
+
router.replace(router.asPath);
|
|
25
43
|
}
|
|
26
44
|
}, [props?.authorized, props?.loading, router]);
|
|
27
45
|
|
|
28
46
|
useEffect(() => {
|
|
29
|
-
if (props?.loading && hasCookie) {
|
|
30
|
-
|
|
47
|
+
if (props?.loading && hasCookie && !reloadAttemptedRef.current) {
|
|
48
|
+
console.log(
|
|
49
|
+
"[withAuth] Cookie available, performing hard reload to bypass cache"
|
|
50
|
+
);
|
|
51
|
+
reloadAttemptedRef.current = true;
|
|
52
|
+
// Hard reload to completely bypass Next.js cache
|
|
53
|
+
if (typeof window !== "undefined") {
|
|
54
|
+
window.location.href = router.asPath;
|
|
55
|
+
}
|
|
31
56
|
}
|
|
32
57
|
}, [props?.loading, hasCookie, router]);
|
|
33
58
|
|
|
@@ -20,7 +20,13 @@ export const withAuthLoader = async <T>(
|
|
|
20
20
|
// Check if auth cookie exists before proceeding
|
|
21
21
|
const authCookie = getAuthCookie(data);
|
|
22
22
|
|
|
23
|
+
console.log("[withAuthLoader] Cookie check:", {
|
|
24
|
+
hasCookie: !!authCookie,
|
|
25
|
+
cookieLength: authCookie?.length,
|
|
26
|
+
});
|
|
27
|
+
|
|
23
28
|
if (!authCookie || authCookie === "") {
|
|
29
|
+
console.log("[withAuthLoader] Returning loading state (no cookie)");
|
|
24
30
|
return {
|
|
25
31
|
authorized: false,
|
|
26
32
|
loading: true,
|
|
@@ -31,7 +37,10 @@ export const withAuthLoader = async <T>(
|
|
|
31
37
|
|
|
32
38
|
const hasAccess = await validateAccessService({ cookie });
|
|
33
39
|
|
|
40
|
+
console.log("[withAuthLoader] Access validation result:", hasAccess);
|
|
41
|
+
|
|
34
42
|
if (!hasAccess) {
|
|
43
|
+
console.log("[withAuthLoader] Access denied, redirecting to /");
|
|
35
44
|
data.res?.writeHead(302, { Location: "/" });
|
|
36
45
|
data.res?.end();
|
|
37
46
|
|
|
@@ -43,6 +52,9 @@ export const withAuthLoader = async <T>(
|
|
|
43
52
|
|
|
44
53
|
const pageData = await dataLoader({ cookie, userId, ...clientContext });
|
|
45
54
|
|
|
55
|
+
console.log(
|
|
56
|
+
"[withAuthLoader] Successfully loaded data, returning authorized"
|
|
57
|
+
);
|
|
46
58
|
return {
|
|
47
59
|
authorized: true,
|
|
48
60
|
data: pageData,
|
|
@@ -50,7 +62,7 @@ export const withAuthLoader = async <T>(
|
|
|
50
62
|
loading: false,
|
|
51
63
|
};
|
|
52
64
|
} catch (error) {
|
|
53
|
-
console.error("Auth validation failed:", error);
|
|
65
|
+
console.error("[withAuthLoader] Auth validation failed:", error);
|
|
54
66
|
|
|
55
67
|
data.res?.writeHead(302, { Location: "/" });
|
|
56
68
|
data.res?.end();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, type ComponentType } from "react";
|
|
1
|
+
import { useEffect, useRef, type ComponentType } from "react";
|
|
2
2
|
|
|
3
3
|
import { useRouter } from "next/router";
|
|
4
4
|
|
|
@@ -19,23 +19,61 @@ export const withAuthProvider = <T,>(
|
|
|
19
19
|
return function WrappedPage(props: AuthRouteProps<T>) {
|
|
20
20
|
const router = useRouter();
|
|
21
21
|
const hasCookie = useCookieMonitor();
|
|
22
|
+
const reloadAttemptedRef = useRef(false);
|
|
23
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
24
|
+
|
|
25
|
+
// Debug logging (only in development or when needed)
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (!isProduction) {
|
|
28
|
+
console.log("[withAuthProvider] Props state:", {
|
|
29
|
+
authorized: props?.authorized,
|
|
30
|
+
loading: props?.loading,
|
|
31
|
+
hasCookie,
|
|
32
|
+
reloadAttempted: reloadAttemptedRef.current,
|
|
33
|
+
routerPath: router.asPath,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}, [
|
|
37
|
+
props?.authorized,
|
|
38
|
+
props?.loading,
|
|
39
|
+
hasCookie,
|
|
40
|
+
router.asPath,
|
|
41
|
+
isProduction,
|
|
42
|
+
]);
|
|
22
43
|
|
|
23
44
|
useEffect(() => {
|
|
24
45
|
// Se não está autorizado e não está carregando, recarrega a página
|
|
25
|
-
if (
|
|
26
|
-
|
|
46
|
+
if (
|
|
47
|
+
!props?.authorized &&
|
|
48
|
+
!props?.loading &&
|
|
49
|
+
!reloadAttemptedRef.current
|
|
50
|
+
) {
|
|
51
|
+
console.log(
|
|
52
|
+
"[withAuthProvider] Reloading: not authorized and not loading"
|
|
53
|
+
);
|
|
54
|
+
reloadAttemptedRef.current = true;
|
|
55
|
+
// Use replace to bypass Next.js data cache
|
|
56
|
+
router.replace(router.asPath);
|
|
27
57
|
}
|
|
28
58
|
}, [props?.authorized, props?.loading, router]);
|
|
29
59
|
|
|
30
60
|
useEffect(() => {
|
|
31
|
-
// If we're in loading state and cookie becomes available,
|
|
32
|
-
if (props?.loading && hasCookie) {
|
|
33
|
-
|
|
61
|
+
// If we're in loading state and cookie becomes available, do hard reload
|
|
62
|
+
if (props?.loading && hasCookie && !reloadAttemptedRef.current) {
|
|
63
|
+
console.log(
|
|
64
|
+
"[withAuthProvider] Cookie available, performing hard reload to bypass cache"
|
|
65
|
+
);
|
|
66
|
+
reloadAttemptedRef.current = true;
|
|
67
|
+
// Hard reload to completely bypass Next.js cache
|
|
68
|
+
if (typeof window !== "undefined") {
|
|
69
|
+
window.location.href = router.asPath;
|
|
70
|
+
}
|
|
34
71
|
}
|
|
35
72
|
}, [props?.loading, hasCookie, router]);
|
|
36
73
|
|
|
37
74
|
if (!props?.authorized) {
|
|
38
75
|
if (props?.loading) {
|
|
76
|
+
console.log("[withAuthProvider] Loading state");
|
|
39
77
|
return <PageLoader />;
|
|
40
78
|
}
|
|
41
79
|
return null;
|