Spaces:
Sleeping
Sleeping
v4.0: Web API analyze route — forward auth token to backend
Browse files- web/app/api/analyze/route.ts +12 -2
web/app/api/analyze/route.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
| 2 |
|
| 3 |
const API_URL = process.env.CLAUSEGUARD_API_URL || "https://gaurv007-clauseguard-api.hf.space";
|
| 4 |
|
|
@@ -14,10 +15,19 @@ export async function POST(req: NextRequest) {
|
|
| 14 |
);
|
| 15 |
}
|
| 16 |
|
| 17 |
-
// Forward
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
const response = await fetch(`${API_URL}/api/analyze`, {
|
| 19 |
method: "POST",
|
| 20 |
-
headers
|
| 21 |
body: JSON.stringify({ text, source_url }),
|
| 22 |
});
|
| 23 |
|
|
|
|
| 1 |
import { NextRequest, NextResponse } from "next/server";
|
| 2 |
+
import { createClient } from "@/lib/supabase/server";
|
| 3 |
|
| 4 |
const API_URL = process.env.CLAUSEGUARD_API_URL || "https://gaurv007-clauseguard-api.hf.space";
|
| 5 |
|
|
|
|
| 15 |
);
|
| 16 |
}
|
| 17 |
|
| 18 |
+
// Forward auth token to backend
|
| 19 |
+
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
| 20 |
+
try {
|
| 21 |
+
const supabase = await createClient();
|
| 22 |
+
const { data: { session } } = await supabase.auth.getSession();
|
| 23 |
+
if (session?.access_token) {
|
| 24 |
+
headers["Authorization"] = `Bearer ${session.access_token}`;
|
| 25 |
+
}
|
| 26 |
+
} catch {}
|
| 27 |
+
|
| 28 |
const response = await fetch(`${API_URL}/api/analyze`, {
|
| 29 |
method: "POST",
|
| 30 |
+
headers,
|
| 31 |
body: JSON.stringify({ text, source_url }),
|
| 32 |
});
|
| 33 |
|