fix: use req.url as redirect base so host is preserved

req.nextUrl.origin resolves to localhost inside the container.
Using req.url preserves the Host header the browser sent, so
redirects work when accessing via IP or any external hostname.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jerick
2026-04-20 16:35:47 -04:00
parent 874b022139
commit 8b0fba5014

View File

@@ -72,13 +72,13 @@ export default auth((req) => {
if (pathname.startsWith('/api/')) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const loginUrl = new URL('/login', req.nextUrl.origin)
const loginUrl = new URL('/login', req.url)
loginUrl.searchParams.set('callbackUrl', pathname)
return NextResponse.redirect(loginUrl)
}
if (pathname === '/login') {
return NextResponse.redirect(new URL('/dashboard', req.nextUrl.origin))
return NextResponse.redirect(new URL('/dashboard', req.url))
}
return NextResponse.next()