File size: 784 Bytes
e3f2df1
 
 
 
 
 
f36152d
e3f2df1
 
 
 
 
 
 
 
 
 
f36152d
 
 
e3f2df1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { createClient } from "@/lib/supabase/server";
import { NextResponse } from "next/server";

export async function GET(request: Request) {
  const requestUrl = new URL(request.url);
  const code = requestUrl.searchParams.get("code");
  const next = requestUrl.searchParams.get("next") || "/dashboard-pages/dashboard";
  const origin = requestUrl.origin;

  if (code) {
    const supabase = await createClient();
    const { error } = await supabase.auth.exchangeCodeForSession(code);
    if (!error) {
      return NextResponse.redirect(`${origin}${next}`);
    }
  }

  // If code exchange failed, try hash-based recovery (password reset flow)
  // Supabase sends recovery tokens as hash fragments which the client handles
  return NextResponse.redirect(`${origin}${next}`);
}