diff --git a/app/page.tsx b/app/page.tsx index fb00506..1913d2b 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -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 }, diff --git a/lib/supabase/middleware.ts b/lib/supabase/middleware.ts index 874d983..1a477b7 100644 --- a/lib/supabase/middleware.ts +++ b/lib/supabase/middleware.ts @@ -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()