cap nhat giao dien

This commit is contained in:
quangdn-ght
2025-06-25 23:25:07 +07:00
parent b07760fbc9
commit ee25e4ac82
10 changed files with 20370 additions and 1165 deletions

View File

@@ -15,6 +15,7 @@ import { handle as siliconflowHandler } from "../../siliconflow";
import { handle as xaiHandler } from "../../xai";
import { handle as chatglmHandler } from "../../glm";
import { handle as proxyHandler } from "../../proxy";
import { handle as supabaseHandler } from "../../supabase";
async function handle(
req: NextRequest,
@@ -27,6 +28,9 @@ async function handle(
console.log(`[${params.provider} Route] params `, params);
switch (apiPath) {
case ApiPath.Supabase:
console.log("[Supabase Route] params ", params);
return supabaseHandler(req, { params });
case ApiPath.Azure:
return azureHandler(req, { params });
case ApiPath.Google:

51
app/api/supabase.ts Normal file
View File

@@ -0,0 +1,51 @@
import { createClient } from "@supabase/supabase-js";
import { NextRequest, NextResponse } from "next/server";
import cookie from "cookie";
const SUPABASE_URL = process.env.SUPABASE_URL!;
const SUPABASE_ANON_KEY = process.env.SUPABASE_ANON_KEY!;
const AUTHEN_PAGE = process.env.AUTHEN_PAGE!;
export async function handle(
req: NextRequest,
{ params }: { params: { path: string[] } },
) {
// Parse cookies using the 'cookie' library
const cookies = cookie.parse(req.headers.get("cookie") || "");
const authToken = cookies["sb-zzgkylsbdgwoohcbompi-auth-token"];
console.log("[Supabase] authToken", authToken);
if (!authToken) {
return NextResponse.redirect(AUTHEN_PAGE, 302);
}
const supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, {
global: {
headers: {
Authorization: `Bearer ${authToken}`,
},
},
});
try {
const { data, error } = await supabase.auth.getUser();
console.log("[Supabase] user", data?.user);
if (error || !data?.user) {
return NextResponse.json(
{ error: error?.message || "Error fetching user data" },
{ status: 401 },
);
}
return NextResponse.json({ user: data.user }, { status: 200 });
} catch (err) {
console.error("Error fetching user data from Supabase:", err);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500 },
);
}
}