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) {
|
||||
const config = await readConfig()
|
||||
const url = req.nextUrl.clone()
|
||||
url.pathname = '/'
|
||||
url.search = ''
|
||||
if (config.authString) {
|
||||
url.searchParams.set('auth', config.authString)
|
||||
}
|
||||
|
||||
// Use x-forwarded-host for proxied requests, fallback to host header
|
||||
const host = req.headers.get('x-forwarded-host') || req.headers.get('host') || 'localhost:3000'
|
||||
const protocol = req.headers.get('x-forwarded-proto') || 'https'
|
||||
|
||||
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