Skip to content

Commit d2b040d

Browse files
committed
feat: ingress base path
1 parent 53d8251 commit d2b040d

File tree

7 files changed

+15
-8
lines changed

7 files changed

+15
-8
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,4 @@ jobs:
6969
platforms: linux/amd64,linux/arm64
7070
build-args: |
7171
BUILDKIT_INLINE_CACHE=1
72+
NEXT_PUBLIC_BASE_PATH=/dashboard

docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ services:
55
args:
66
- MONGODB_URI=${MONGODB_URI}
77
- MONGODB_DB_NAME=${MONGODB_DB_NAME}
8+
- NEXT_PUBLIC_BASE_PATH=/dashboard
89
container_name: nextjs_app
910
ports:
1011
- "3000:3000"

next.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { NextConfig } from "next";
22

3-
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "";
3+
const basePath = process.env.NEXT_PUBLIC_BASE_PATH || "/dashboard";
44

55
const nextConfig: NextConfig = {
66
output: "standalone",
7-
basePath: basePath.length > 0 ? basePath : undefined,
8-
assetPrefix: basePath.length > 0 ? basePath : undefined,
7+
basePath: basePath,
8+
assetPrefix: basePath,
99
poweredByHeader: false,
1010
reactStrictMode: true,
1111
images: {
@@ -38,7 +38,7 @@ const nextConfig: NextConfig = {
3838
{
3939
source: "/",
4040
destination: "/dashboard",
41-
permanent: true,
41+
permanent: false,
4242
},
4343
];
4444
},

src/app/login/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export default function LoginPage() {
4444
if (response.ok) {
4545
setPassword(""); // Clear password from memory
4646
// Force a full page reload to reset AuthGuard state
47-
window.location.href = "/dashboard";
47+
window.location.href = "/dashboard/dashboard";
4848
} else {
4949
const data = await response.json();
5050
setError(data.error || "Authentication failed. Please try again.");

src/app/page.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { redirect } from "next/navigation";
22

33
export default function RootPage() {
4+
// When basePath is set to /dashboard, this page will be at /dashboard
5+
// Redirect to /dashboard/dashboard for consistency, but next.config.ts
6+
// already handles / -> /dashboard redirect
47
redirect("/dashboard");
58
}

src/components/auth/auth-guard.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ interface AuthGuardProps {
1010
}
1111

1212
// Public routes that don't require authentication
13-
const PUBLIC_ROUTES = ["/login"];
13+
// Note: These are without basePath prefix - usePathname already includes basePath
14+
const PUBLIC_ROUTES = ["/login", "/dashboard/login"];
1415

1516
export default function AuthGuard({ children }: AuthGuardProps) {
1617
const [isAuthenticated, setIsAuthenticated] = useState<boolean | null>(null);
@@ -51,7 +52,7 @@ export default function AuthGuard({ children }: AuthGuardProps) {
5152
if (!isAuthenticated && !isPublicRoute) {
5253
// Not authenticated and trying to access protected route
5354
isRedirecting.current = true;
54-
router.replace("/login");
55+
router.replace("/dashboard/login");
5556
} else if (isAuthenticated && isPublicRoute) {
5657
// Authenticated but on login page, redirect to dashboard
5758
isRedirecting.current = true;

src/components/dashboard/logout-button.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default function LogoutButton() {
1717

1818
if (response.ok) {
1919
// Force reload to clear all state and redirect to login
20-
window.location.href = "/";
20+
// Next.js basePath handles the redirect automatically
21+
window.location.href = "/dashboard/login";
2122
}
2223
} catch (error) {
2324
console.error("Logout failed:", error);

0 commit comments

Comments
 (0)