* Handles authentication-based redirects for root paths
( request: NextRequest, hasActiveSession: boolean )
| 129 | * Handles authentication-based redirects for root paths |
| 130 | */ |
| 131 | function handleRootPathRedirects( |
| 132 | request: NextRequest, |
| 133 | hasActiveSession: boolean |
| 134 | ): NextResponse | null { |
| 135 | const url = request.nextUrl |
| 136 | |
| 137 | if (url.pathname !== '/') { |
| 138 | return null |
| 139 | } |
| 140 | |
| 141 | if (!isHosted) { |
| 142 | // Self-hosted: Always redirect based on session |
| 143 | if (hasActiveSession) { |
| 144 | return NextResponse.redirect(new URL('/workspace', request.url)) |
| 145 | } |
| 146 | return NextResponse.redirect(new URL('/login', request.url)) |
| 147 | } |
| 148 | |
| 149 | // For root path, redirect authenticated users to workspace |
| 150 | // Unless they have a 'home' query parameter (e.g., ?home) |
| 151 | // This allows intentional navigation to the homepage from anywhere in the app |
| 152 | if (hasActiveSession) { |
| 153 | const isBrowsingHome = url.searchParams.has('home') |
| 154 | if (!isBrowsingHome) { |
| 155 | return NextResponse.redirect(new URL('/workspace', request.url)) |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | return null |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Handles invitation link redirects for unauthenticated users |