File tree Expand file tree Collapse file tree 7 files changed +15
-8
lines changed
Expand file tree Collapse file tree 7 files changed +15
-8
lines changed Original file line number Diff line number Diff line change 6969 platforms : linux/amd64,linux/arm64
7070 build-args : |
7171 BUILDKIT_INLINE_CACHE=1
72+ NEXT_PUBLIC_BASE_PATH=/dashboard
Original file line number Diff line number Diff 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"
Original file line number Diff line number Diff line change 11import 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
55const 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 } ,
Original file line number Diff line number Diff 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." ) ;
Original file line number Diff line number Diff line change 11import { redirect } from "next/navigation" ;
22
33export 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}
Original file line number Diff line number Diff 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
1516export 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 ;
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments