Add tenant_id to users table and admin tenants API endpoint
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s
All checks were successful
Trigger Cloudarix Deploy / call-webhook (push) Successful in 1s
This commit is contained in:
parent
e1df2a98dd
commit
e0a746b29c
23
app/api/admin/tenants/route.ts
Normal file
23
app/api/admin/tenants/route.ts
Normal 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);
|
||||||
|
}
|
||||||
@ -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(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user