2026-01-05 09:58:59 +07:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
|
import { getProviderConnections } from "@/lib/localDb";
|
2026-04-24 11:36:16 +07:00
|
|
|
import { backfillCodexEmails } from "@/lib/oauth/providers";
|
2026-01-05 09:58:59 +07:00
|
|
|
|
|
|
|
|
// GET /api/providers/client - List all connections for client (includes sensitive fields for sync)
|
|
|
|
|
export async function GET() {
|
|
|
|
|
try {
|
2026-04-24 11:36:16 +07:00
|
|
|
await backfillCodexEmails();
|
2026-01-05 09:58:59 +07:00
|
|
|
const connections = await getProviderConnections();
|
|
|
|
|
|
|
|
|
|
// Include sensitive fields for sync to cloud (only accessible from same origin)
|
|
|
|
|
const clientConnections = connections.map(c => ({
|
|
|
|
|
...c,
|
|
|
|
|
// Don't hide sensitive fields here since this is for internal sync
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
return NextResponse.json({ connections: clientConnections });
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.log("Error fetching providers for client:", error);
|
|
|
|
|
return NextResponse.json({ error: "Failed to fetch providers" }, { status: 500 });
|
|
|
|
|
}
|
|
|
|
|
}
|