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:
@@ -72,13 +72,13 @@ export default auth((req) => {
|
|||||||
if (pathname.startsWith('/api/')) {
|
if (pathname.startsWith('/api/')) {
|
||||||
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
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)
|
loginUrl.searchParams.set('callbackUrl', pathname)
|
||||||
return NextResponse.redirect(loginUrl)
|
return NextResponse.redirect(loginUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pathname === '/login') {
|
if (pathname === '/login') {
|
||||||
return NextResponse.redirect(new URL('/dashboard', req.nextUrl.origin))
|
return NextResponse.redirect(new URL('/dashboard', req.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
return NextResponse.next()
|
return NextResponse.next()
|
||||||
|
|||||||
Reference in New Issue
Block a user