fix(auth): redirect to appUrl after invite callback

origin lacks /ims basePath; use NEXT_PUBLIC_APP_URL instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BzvzV91UqHZKM9P58qtvrA
This commit is contained in:
2026-07-16 21:44:12 +08:00
co-authored by Claude Sonnet 4.6
parent b08fec385d
commit e682162bbc
3 changed files with 28 additions and 4 deletions
+4 -3
View File
@@ -3,18 +3,19 @@ import { createClient } from '@/lib/supabase/server'
import { NextResponse } from 'next/server'
export async function GET(request: Request) {
const { searchParams, origin } = new URL(request.url)
const { searchParams } = new URL(request.url)
const code = searchParams.get('code')
const nextRaw = searchParams.get('next') ?? '/'
const next = nextRaw.startsWith('/') && !nextRaw.startsWith('//') ? nextRaw : '/'
const appUrl = (process.env.NEXT_PUBLIC_APP_URL ?? '').replace(/\/$/, '')
if (code) {
const supabase = await createClient()
const { error } = await supabase.auth.exchangeCodeForSession(code)
if (!error) {
return NextResponse.redirect(`${origin}${next}`)
return NextResponse.redirect(`${appUrl}${next}`)
}
}
return NextResponse.redirect(`${origin}/login?error=auth_callback_failed`)
return NextResponse.redirect(`${appUrl}/login?error=auth_callback_failed`)
}