Add tenant_id to users table and admin tenants API endpoint
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s

This commit is contained in:
Ahmed Darrazi 2025-12-06 00:35:02 +01:00
parent e1df2a98dd
commit e0a746b29c
2 changed files with 24 additions and 0 deletions

View File

@ -0,0 +1,23 @@
import { db } from "@/lib/db";
import { users } from "@/lib/db/schema/auth";
import { NextResponse } from "next/server";
import { isNotNull } from "drizzle-orm";
export async function GET(req: Request) {
const authHeader = req.headers.get("x-api-secret");
// Wir nutzen dasselbe Secret wie für die Ingestion API
if (authHeader !== process.env.POLICY_API_SECRET) {
return new NextResponse("Unauthorized", { status: 401 });
}
// Hole alle einzigartigen Tenant-IDs aus der User-Tabelle
const tenants = await db
.selectDistinct({ tenantId: users.tenantId })
.from(users)
.where(isNotNull(users.tenantId));
// Wir filtern 'common' raus, falls es drin ist
const cleanList = tenants.filter(t => t.tenantId !== 'common');
return NextResponse.json(cleanList);
}

View File

@ -13,6 +13,7 @@ export const users = pgTable("user", {
email: text("email").notNull(), email: text("email").notNull(),
emailVerified: timestamp("emailVerified", { mode: "date" }), emailVerified: timestamp("emailVerified", { mode: "date" }),
image: text("image"), image: text("image"),
tenantId: text("tenant_id"),
}); });
export const accounts = pgTable( export const accounts = pgTable(