feat: redirect code parameter to auth callback in middleware\n\nAdapt middleware to handle parameter and route to .

This commit is contained in:
v0 2026-02-07 01:35:13 +00:00
parent e8a65645c2
commit 7bc69a7a36
2 changed files with 21 additions and 1 deletions

View File

@ -1,7 +1,18 @@
import { redirect } from "next/navigation"
import { createClient } from "@/lib/supabase/server"
export default async function Page() {
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ code?: string }>
}) {
const params = await searchParams
// If there's an auth code, redirect to callback to exchange it
if (params.code) {
redirect(`/auth/callback?code=${params.code}`)
}
const supabase = await createClient()
const {
data: { user },

View File

@ -29,6 +29,15 @@ export async function updateSession(request: NextRequest) {
},
)
// Intercept auth confirmation codes on any route and redirect to callback
const code = request.nextUrl.searchParams.get('code')
if (code && !request.nextUrl.pathname.startsWith('/auth/callback')) {
const url = request.nextUrl.clone()
url.pathname = '/auth/callback'
url.searchParams.set('code', code)
return NextResponse.redirect(url)
}
const {
data: { user },
} = await supabase.auth.getUser()