mirror of https://github.com/kortix-ai/suna.git
Merge pull request #1391 from ffrankan/fix/auth-callback-self-hosted-redirect
Fix auth callback redirect issues in self-hosted deployments
This commit is contained in:
commit
5e1e82f67a
|
@ -3,15 +3,18 @@ import { NextResponse } from 'next/server'
|
|||
import type { NextRequest } from 'next/server'
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
const { searchParams, origin } = new URL(request.url)
|
||||
const { searchParams } = new URL(request.url)
|
||||
const code = searchParams.get('code')
|
||||
const next = searchParams.get('next') ?? '/dashboard'
|
||||
const next = searchParams.get('returnUrl') ?? '/dashboard'
|
||||
|
||||
// Use configured URL instead of parsed origin to avoid 0.0.0.0 issues in self-hosted environments
|
||||
const baseUrl = process.env.NEXT_PUBLIC_URL || 'http://localhost:3000'
|
||||
const error = searchParams.get('error')
|
||||
const errorDescription = searchParams.get('error_description')
|
||||
|
||||
if (error) {
|
||||
console.error('❌ Auth callback error:', error, errorDescription)
|
||||
return NextResponse.redirect(`${origin}/auth?error=${encodeURIComponent(error)}`)
|
||||
return NextResponse.redirect(`${baseUrl}/auth?error=${encodeURIComponent(error)}`)
|
||||
}
|
||||
|
||||
if (code) {
|
||||
|
@ -22,15 +25,15 @@ export async function GET(request: NextRequest) {
|
|||
|
||||
if (error) {
|
||||
console.error('❌ Error exchanging code for session:', error)
|
||||
return NextResponse.redirect(`${origin}/auth?error=${encodeURIComponent(error.message)}`)
|
||||
return NextResponse.redirect(`${baseUrl}/auth?error=${encodeURIComponent(error.message)}`)
|
||||
}
|
||||
|
||||
// URL to redirect to after sign in process completes
|
||||
return NextResponse.redirect(`${origin}${next}`)
|
||||
return NextResponse.redirect(`${baseUrl}${next}`)
|
||||
} catch (error) {
|
||||
console.error('❌ Unexpected error in auth callback:', error)
|
||||
return NextResponse.redirect(`${origin}/auth?error=unexpected_error`)
|
||||
return NextResponse.redirect(`${baseUrl}/auth?error=unexpected_error`)
|
||||
}
|
||||
}
|
||||
return NextResponse.redirect(`${origin}/auth`)
|
||||
return NextResponse.redirect(`${baseUrl}/auth`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue