From cc921a91e12674ed2d099934fce9d1ecdc1613ac Mon Sep 17 00:00:00 2001 From: dyzulk <66510723+dyzulk@users.noreply.github.com> Date: Mon, 5 Jan 2026 23:26:45 +0700 Subject: [PATCH] fix: stop 401 auth retry loop and remove unsafe PNA localhost fallback --- src/components/Layouts/Public/Footer.tsx | 4 ++-- src/hooks/useAuth.ts | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/components/Layouts/Public/Footer.tsx b/src/components/Layouts/Public/Footer.tsx index d3d299d..f5b8678 100644 --- a/src/components/Layouts/Public/Footer.tsx +++ b/src/components/Layouts/Public/Footer.tsx @@ -16,8 +16,8 @@ export default function Footer() { useEffect(() => { const fetchLegalPages = async () => { try { - // Use public API endpoint - const apiUrl = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8000'; + // Use public API endpoint code with backup + const apiUrl = process.env.NEXT_PUBLIC_API_URL || process.env.NEXT_PUBLIC_API_URL_BACKUP || 'https://api.trustlab.dyzulk.com'; const res = await fetch(`${apiUrl}/api/public/legal-pages`, { headers: { 'Accept': 'application/json' } }); diff --git a/src/hooks/useAuth.ts b/src/hooks/useAuth.ts index 7e5a258..ff9f274 100644 --- a/src/hooks/useAuth.ts +++ b/src/hooks/useAuth.ts @@ -13,7 +13,22 @@ export const useAuth = ({ middleware, redirectIfAuthenticated }: { middleware?: .catch(error => { if (error.response.status !== 409) throw error; router.push('/verify-email'); - }) + }), + { + onErrorRetry: (error, key, config, revalidate, { retryCount }) => { + // Never retry on 401 Unauthorized + if (error.response?.status === 401) return; + + // Never retry on 409 Conflict (handled by catch block above) + if (error.response?.status === 409) return; + + // Only retry up to 3 times for other errors + if (retryCount >= 3) return; + + // Retry after 5 seconds + setTimeout(() => revalidate({ retryCount }), 5000); + } + } ); const csrf = () => axios.get('/sanctum/csrf-cookie');