From 17ee3ec99a5ef38e1c41f88a32203f8601e45fc6 Mon Sep 17 00:00:00 2001 From: bfium Date: Fri, 5 Dec 2025 09:56:11 +0100 Subject: [PATCH] fix: ensure frontend waits for backend and redirect unauthenticated users - Add depends_on to frontend service to wait for backend healthcheck - Add beforeLoad guard to dashboard route to redirect to login when not authenticated - Prevents nginx 'host not found' errors and infinite loading spinner --- docker-compose.override.yml | 3 +++ frontend/src/routes/_layout/index.tsx | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/docker-compose.override.yml b/docker-compose.override.yml index 0751abe901..7fcea21788 100644 --- a/docker-compose.override.yml +++ b/docker-compose.override.yml @@ -101,6 +101,9 @@ services: args: - VITE_API_URL=http://localhost:8000 - NODE_ENV=development + depends_on: + backend: + condition: service_healthy playwright: build: diff --git a/frontend/src/routes/_layout/index.tsx b/frontend/src/routes/_layout/index.tsx index 66e32e0b30..ab23f4e11e 100644 --- a/frontend/src/routes/_layout/index.tsx +++ b/frontend/src/routes/_layout/index.tsx @@ -1,10 +1,17 @@ import { Box, Container, Text } from "@chakra-ui/react" -import { createFileRoute } from "@tanstack/react-router" +import { createFileRoute, redirect } from "@tanstack/react-router" -import useAuth from "@/hooks/useAuth" +import useAuth, { isLoggedIn } from "@/hooks/useAuth" export const Route = createFileRoute("/_layout/")({ component: Dashboard, + beforeLoad: async () => { + if (!isLoggedIn()) { + throw redirect({ + to: "/login", + }) + } + }, }) function Dashboard() {