Skip to content

Commit 17ee3ec

Browse files
committed
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
1 parent 61b7cd6 commit 17ee3ec

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

docker-compose.override.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ services:
101101
args:
102102
- VITE_API_URL=http://localhost:8000
103103
- NODE_ENV=development
104+
depends_on:
105+
backend:
106+
condition: service_healthy
104107

105108
playwright:
106109
build:

frontend/src/routes/_layout/index.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import { Box, Container, Text } from "@chakra-ui/react"
2-
import { createFileRoute } from "@tanstack/react-router"
2+
import { createFileRoute, redirect } from "@tanstack/react-router"
33

4-
import useAuth from "@/hooks/useAuth"
4+
import useAuth, { isLoggedIn } from "@/hooks/useAuth"
55

66
export const Route = createFileRoute("/_layout/")({
77
component: Dashboard,
8+
beforeLoad: async () => {
9+
if (!isLoggedIn()) {
10+
throw redirect({
11+
to: "/login",
12+
})
13+
}
14+
},
815
})
916

1017
function Dashboard() {

0 commit comments

Comments
 (0)