Update redirect flow
This commit is contained in:
parent
737998bd6d
commit
56b68a5b19
1 changed files with 8 additions and 7 deletions
|
|
@ -3,12 +3,13 @@ import { readConfig } from '@/utils/config'
|
||||||
|
|
||||||
export async function GET(req: NextRequest) {
|
export async function GET(req: NextRequest) {
|
||||||
const config = await readConfig()
|
const config = await readConfig()
|
||||||
const url = req.nextUrl.clone()
|
|
||||||
url.pathname = '/'
|
// Use x-forwarded-host for proxied requests, fallback to host header
|
||||||
url.search = ''
|
const host = req.headers.get('x-forwarded-host') || req.headers.get('host') || 'localhost:3000'
|
||||||
if (config.authString) {
|
const protocol = req.headers.get('x-forwarded-proto') || 'https'
|
||||||
url.searchParams.set('auth', config.authString)
|
|
||||||
}
|
const redirectPath = config.authString ? `/?auth=${config.authString}` : '/'
|
||||||
|
const redirectUrl = new URL(redirectPath, `${protocol}://${host}`)
|
||||||
|
|
||||||
return NextResponse.redirect(url)
|
return NextResponse.redirect(redirectUrl)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue