fix: update the permission for viewing provider pages

This commit is contained in:
2026-07-15 17:56:14 +07:00
parent 4b0acbfc69
commit 5c8d9f80b0
45 changed files with 362 additions and 340 deletions
+9 -3
View File
@@ -48,9 +48,9 @@ async function normalizeProxyPoolId(proxyPoolId) {
}
// GET /api/providers - List all connections
export async function GET() {
export async function GET(request) {
try {
const { ownerId } = await getProviderConnectionAccess();
const { ownerId } = await getProviderConnectionAccess(request);
const connections = await getProviderConnections(ownerId ? { ownerId } : {});
// Build nodeNameMap for compatible providers (id → name)
@@ -83,6 +83,9 @@ export async function GET() {
if (error.message === "Unauthorized") {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (error.message === "Forbidden") {
return NextResponse.json({ error: "Administrator access required" }, { status: 403 });
}
console.log("Error fetching providers:", error);
return NextResponse.json({ error: "Failed to fetch providers" }, { status: 500 });
}
@@ -91,7 +94,7 @@ export async function GET() {
// POST /api/providers - Create new connection (API Key only, OAuth via separate flow)
export async function POST(request) {
try {
const { user } = await getProviderConnectionAccess();
const { user } = await getProviderConnectionAccess(request);
const body = await request.json();
const provider = normalizeProviderId(body.provider);
const { apiKey, name, displayName, priority, globalPriority, defaultModel, testStatus } = body;
@@ -205,6 +208,9 @@ export async function POST(request) {
if (error.message === "Unauthorized") {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
if (error.message === "Forbidden") {
return NextResponse.json({ error: "Administrator access required" }, { status: 403 });
}
console.log("Error creating provider:", error);
return NextResponse.json(
{ error: error.status === 409 ? error.message : "Failed to create provider" },